Solved

call or set variable value with variable name stored in string

Posted on 2010-09-03
5
397 Views
Last Modified: 2012-05-10
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
Comment
Question by:_Tommy_b
5 Comments
 
LVL 12

Expert Comment

by:rajapandian_81
ID: 33594806
Remove double quote near value and try.

Dim VarName as String = value

Open in new window

0
 

Author Comment

by:_Tommy_b
ID: 33594859
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
 
LVL 10

Accepted Solution

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

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

0
 

Author Comment

by:_Tommy_b
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,

Tommy
0
 
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - KeyPress Event 4 38
VB.NET 2008 Publish Error 2 32
System.net.Sockets Error 5 26
Toolbar to format all windows forms controls at design time needed 5 13
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 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