Question Variable Issues

Joined
Apr 11, 2010
Messages
1
Programming Experience
Beginner
I'm kind of a newbie so I apologize in advance. I am taking an Introduction to VB course and am attempting to work on my final project. It’s due in 6 weeks so I have some time, but have been having some problems.

I have defined 5 variables T1, T2, T3, T4, T5 As Double and set them all = 0. On a form I have a enter information button. Each time the button is pressed I want to assign a different variable, to a text box’s input. For instance, If I enter 1 that will become T1, and then if I enter 2 and press the button again, that value becomes T2.

I have tried

If T1 = 0 then
T1 = textbox.text
End if
If T1<>0 And T2 = 0 then
T2 = textbox.text
End if

I have tried to use “else” statements and all kinds of things like that to no avail. I can get the first two variables correctly assigned but three is impossible with my current understanding. Is there a way to do this, or do I need 5 buttons, so that I can control which variable is assigned?

To be correct my intent is to create an observation with three variables each time the button is pressed. For example, the first button press will result in three variables being assigned a value other than 0; they are T1, B1, and R1. I have just begun to understand the concept of arrays and am wondering if that may be the way to go in this situation. I was just going at this in a newbie way I'm sure and trying to handle each variable type individually, and figure out all the T* variables and move onto the B* variables.

Thanks for any help,

Josh
 
In cases like this, where you want to treat values as a set, you should use an array rather than discrete variables:
VB.NET:
Dim values(4) As Double
You can now refer to each element by index or use a For each loop to visit each element in turn. In your case, you might have a separate Integer variable that contains the index of the next element to set. Each time you set an element you increment that counter. If it goes beyond the upper bound you can wrap back to 0 and start again, if that's appropriate.
 
Back
Top