Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

complex referals/variable names like string(cnt)

Status
Not open for further replies.

xhonzi

Programmer
Jul 29, 2003
196
US
So,
I have a series of boxes names string0, string1, string2, etc.

I'm trying to assign values in a loop and I wanted to refer to them as string(cnt) and that doesn't work in VBA. Is there a proper syntax for this in VBA, or do I just need to go back to Perl?

Code:
for cnt = 0 to 10
  me.string(cnt).value = cnt
next

So, yeah this doesn't work. Am I missing something?

xhonzi
 
You can't do this that way in VBA. You can define an array of strings:
Code:
[blue]Dim MyString(0 To 10) As String[/blue]
and then code with a variable for the array index:
Code:
[blue]For cnt = 0 To 10
    MyString(cnt) = cnt
Next cnt[/blue]
but you can't dynamically generate variable names.


Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Replace this:
me.string(cnt).value = cnt
with this:
Me.Controls("string" & cnt).Value = cnt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top