Vb.net variable name

I have 3 variables and i need make a loop like ex.:

var1, var2,var3

for i=1 to 3
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
that can't be done this way. You might use an array: http://msdn.microsoft.com/en-us/library/vstudio/wak0wfyt.aspx
Fernando SotoRetiredCommented:
Hi rflorencio;

As emoreau has pointed out what you want to do can NOT be done with modifying a variable name by concatinating another string to it. You can accomplish this by using an array as shown below.

' Create an array of type integer. Please note the (2) defines the array with
' three elements. Arrays start the index at zero so the elements are 
' 0, 1 and 2. The value in (2) tells us that the last index in the array that
' can be access is index 2.
Dim vars(2) As Integer

' Setting up the loop to access all elements of the array. Note that it starts
' at 0 and NOT 1 as in your code and goes to the last index of 2
For i As Integer = 0 To 2
    vars(i) = 1

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can use Reflection or CallByName() (the latter only under certain circumstances).

But without further information the other approaches given already are probably a better design...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.