_Tommy_b
asked on
call or set variable value with variable name stored in string
Hi,
I'm looking to call or set the value of a variable with the variable name stored as a string.
for example,
Dim value as String = "12345"
Dim VarName as String = "value"
Messagebox.show( someprocedure(VarName) )
' in this case i world be looking a message box containing: 12345
this examble does not reflect what i need this function for... I need to be able to loop though
multiple values and call / set there values.
Any help would be appresiated.
Thanks,
Tommy
I'm looking to call or set the value of a variable with the variable name stored as a string.
for example,
Dim value as String = "12345"
Dim VarName as String = "value"
Messagebox.show( someprocedure(VarName) )
' in this case i world be looking a message box containing: 12345
this examble does not reflect what i need this function for... I need to be able to loop though
multiple values and call / set there values.
Any help would be appresiated.
Thanks,
Tommy
ASKER
Hello rajapandian,
Sorry perhaps i never made clear what i was asking.
I have multiple variables:
b1
b2
b3
b4
ect......
I need to loop though each variable in and obtain or set a value this is what i have so far, i just need to know how to reference the variable using the string?
Thanks,
Tommy
Sorry perhaps i never made clear what i was asking.
I have multiple variables:
b1
b2
b3
b4
ect......
I need to loop though each variable in and obtain or set a value this is what i have so far, i just need to know how to reference the variable using the string?
Thanks,
Tommy
Dim co As Integer
Dim str As String
co = 1
Do Until co = i
str = "b" & co.ToString
' I now need to assign a value to a variable with the name specifyed in the string str
i = i+1
Loop
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks joriszwaenepoel,
Am new to programming and never thought of using an array...
This seams to be the soloution to my problem.
Again thank you very much..
Kind Regards,
Tommy
Am new to programming and never thought of using an array...
This seams to be the soloution to my problem.
Again thank you very much..
Kind Regards,
Tommy
*Just for the record, it is possible to do what your asking using REFLECTION...but we'd really need to know more about your application to decide which approach best fits your needs.
Open in new window