Question Concatanation of a variable name

mr_sarge

New member
Joined
Jan 30, 2009
Messages
2
Programming Experience
Beginner
Hi,

Is it possible to do a concatanation of a variable name itself?

Ex:
I want to turn 5 variable to 0
VB.NET:
Expand Collapse Copy
De1Lock = 0
De2Lock = 0
De3Lock = 0
De4Lock = 0
De5Lock = 0

I would like something like:
VB.NET:
Expand Collapse Copy
For i = 1 To 5
De[i]Lock = 0
Next

Is There a way to do that in VB.Net ?

Thanks
 
I suspect this is possible using Reflection.

You may want to look at your program design if this is something that you plan on doing. An array or List(Of Integer) would be a much better choice in this situation.
 
Ok I have try:
VB.NET:
Expand Collapse Copy
Public DeLock() As Integer = {1, 2, 3, 2, 1}

and do
VB.NET:
Expand Collapse Copy
DeLock = New Integer() {0, 0, 0, 0, 0}

To reset it to zero.

Is there something better or this is ok ?

Anf If I want to do the same thing but with Label.Text ?
VB.NET:
Expand Collapse Copy
        Form1.Label1.Text = "0"
        Form1.Label2.Text = "0"
        Form1.Label3.Text = "0"
        Form1.Label4.Text = "0"
        Form1.Label5.Text = "0"
 
Back
Top