Link to home
Start Free TrialLog in
Avatar of _Tommy_b
_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
Avatar of rajapandian_81
rajapandian_81
Flag of India image

Remove double quote near value and try.

Dim VarName as String = value

Open in new window

Avatar of _Tommy_b
_Tommy_b

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
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of joriszwaenepoel
joriszwaenepoel
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of Mike Tomlinson
*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.