Use string value as variable name
How do I use a value of a string as a public variable name/object that I can then change....
dim var1 as integer
dim var2 as integer
dim var3 as integer...ect...
Dim vroot as string = "var"
Dim i as integer = 1
Do
var + i.tostring
'this returns "var1"
'now how do i use this var1 returned value to act like a variable?
i=i+1
loop until i = 15
Also how would i do this with objects....say i had a series of labels named label1, labe2, label3...ect... to call these through a"label + i.tostring + .text" script also......
Catch my drift....is this possible?
Thanks!
As papdi writes above, if the "variables" that you are playing with happen to be controls that are placed on a form or user control, then they are already part of a collection (the controls collection of the form or user control)
You can access the controls by name from within the parent either by name or by index:
| | Me.Controls(<control name>) |
If this we are talking about normal variables, then I'd be boring and strongly suggest using a collection. If you could give us some more information about what you are trying to accomplish, we may be able to come up with a solution that is dynamic enough for your needs 
Best regards,
Johan Stenberg
If you get an answer that works for this I would appreciate hearing from you. I have tried the HashTable that was mentioned and every other collection type I can think of.
If anyone has an answer please let me know.
Thanks in advance,
Rich
For the issue with variable names, here is some code from VB.Net 2003. Note that the collection is actually a collection of objects, so you can't assume (for example) that the variable stored is an integer, a string, etc.
Dim MyVariables As New Collection
With MyVariables
.Add("1", "Var1")
.Add("2", "Var2")
.Add("3", "Var3")
End With
' Const strRoot As String = "Var" Dim intIdx As Integer For intIdx = 1 To 3 MsgBox(MyVariables(strRoot & intIdx))
Next For the issue with controls, in VB.Net 2003 I was getting an error trying to access the control collection by control name. Instead, this would work (assuming you have three labels named Label1, Label2, and Label3):
Const strControl As String = "Label" Dim ctl As Control For intIdx = 1 To 3 For Each ctl In Me.Controls If ctl.Name = strControl & intIdx Then MsgBox(ctl.Text)
End If Next Next