Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 407
  • Last Modified:

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
0
_Tommy_b
Asked:
_Tommy_b
1 Solution
 
rajapandian_81Commented:
Remove double quote near value and try.

Dim VarName as String = value

Open in new window

0
 
_Tommy_bAuthor Commented:
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

0
 
joriszwaenepoelCommented:
I don't know of any way to get a reference to a variable using its name as as string.

Can't you put them in an array of List?
Then you can reference them with their index:

b(0)
b(1)
b(2)

0
 
_Tommy_bAuthor Commented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
*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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now