Question Using a variable as part of a control name...

d3c4y

New member
Joined
Jul 25, 2009
Messages
2
Programming Experience
1-3
Hey,

My apologies if this question seems a little disjointed, I'll do my best to get it across.

Basically, I have a large number of text boxes. Within these text boxes, I'll be doing calculations based on user input and other things. These boxes will be grouped by numbers, eg Cost1, Profit1, Stock1... Cost26, Profit26, Stock26

Without too much explanation, I went to write a FOR loop to perform a repetitive calculation across multiple groups, and the following line came up.

FOR num = 1 TO 26

Cost(num).text = ItemCost

What I've tried to do is use a variable to decide which 'Cost' textbox, from the available 26, to use in the calculation. For whatever reason, it won't work.


I would like to be able to use a variable to specify exactly which textboxes I want used, so that on the 3rd pass of the loop, the 3rd box is used, and on the 19th pass, the 19th box is used.

Otherwise, I'd just have to do each calculation seperately, and write the same thing 26 times, with slightly different numbers.


Can anyone offer any help?


Thanks very much.
 
If they're in the forms Controls collection:
VB.NET:
Me.Controls("Cost" & num.ToString).Text = ItemCost.ToString
 
Back
Top