Solved

call or set variable value with variable name stored in string

Posted on 2010-09-03
5
388 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

12 Experts available now in Live!

Get 1:1 Help Now