|
Subject:
|
textbox names wth numbers
|
|
Posted By:
|
popweasel
|
Post Date:
|
1/2/2006 7:16:31 AM
|
hello.
i have 9 text boxes.
named txtbox00 , txtbox01 , txtbox02. etc they continue up until txtbox22. they are a grid layout.
and i want to loop through them using for loops, getting them to store what is in an array, but this does not work.
this is what i am tying to do in the code
For x = 0 To 2 For y = 0 To 2
txtboxxy = grid(x, y)
Next Next
i have tried some different things all do not work. like using brackets and apostrophes.
any help thanks.
|
|
Reply By:
|
marcostraf
|
Reply Date:
|
1/3/2006 5:50:52 PM
|
the best way to do this is to change your 2x2 text boxes into an array. Name the first text box like you want (txtbox is ok, but it does not say what is used for, be more verbose) and set its Index property to 0. Rename the second with the same name, and VB will automatically set the Index property to 1, and continue for all text boxes. Now the loop will be:
set txtboxxy = txtbox(x + y* numberOfColumns)
As an alternative, you can use the Controls property to get a control by name:
set txtboxxy = me.controls("txtbox" & format(x,"00") & format(y,"00")
My preferred way will be to use a MSFlexGrid instead of a bunch of textBoxes (this is what a grid is for: to display values in a... grid)
PS: all the code is not tested PPS: remember to use the "set" keyword to assign an object to a variable
Marco
|