2 Replies - 740 Views - Last Post: 07 November 2011 - 07:02 AM Rate Topic: -----

#1 TurboGLH  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-November 11

Creating variables based on textbox input

Posted 06 November 2011 - 08:59 PM

Another vb.net newbie, so this may be easy but I can't find any info around.

I have a form with a few text boxes, one of which has it's contents stored to a integer variable.

The value stored will end up being one of a few numbers ranging from 12 to 98, and I need to the same number of new variables as the number in the textbox.

Can I automate the creation of new variables based on the value stored, or do I need to define the max number required and just ignore the rest when using less?

Is This A Good Question/Topic? 0
  • +

Replies To: Creating variables based on textbox input

#2 Tryparse  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 80
  • View blog
  • Posts: 193
  • Joined: 20-April 10

Re: Creating variables based on textbox input

Posted 06 November 2011 - 09:11 PM

The easiest way to dynamically create variables is by using arrays or collections. A List is especially handy if you don't know how many you'll need, and may need to add or remove variables at runtime.
Dim lstInts As New List(Of Integer)
lstInts.Add(1)
lstInts.Add(5)
lstInts.Add(intValue)
lstInts.Add(Integer.Parse(TextBox1.Text))

Was This Post Helpful? 1
  • +
  • -

#3 TurboGLH  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-November 11

Re: Creating variables based on textbox input

Posted 07 November 2011 - 07:02 AM

lstInts.Add(Integer.Parse(TextBox1.Text))


That seems like just the guy I need to do the trick. Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1