call or set variable value with variable name stored in string

Posted on 2010-09-03
Last Modified: 2012-05-10

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


Question by:_Tommy_b
LVL 12

Expert Comment

ID: 33594806
Remove double quote near value and try.

Dim VarName as String = value

Open in new window


Author Comment

ID: 33594859
Hello rajapandian,

Sorry perhaps i never made clear what i was asking.

I have multiple variables:


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?


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


Open in new window

LVL 10

Accepted Solution

joriszwaenepoel earned 500 total points
ID: 33595070
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:



Author Comment

ID: 33595096
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,

LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33598678
*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.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now