loops controls

Shihtzu

Member
Joined
Nov 24, 2006
Messages
16
Programming Experience
Beginner
say if I have these few labels

lbl1
lbl2
lbl3

inside the loop

for count from 1 to 3

how do I change the lbl1 and lbl2 and lbl3.text accordingly inside the loop?
I tried lbl doesn't work as well.

Many help appreciated :D
 
lol1, lol2 , lol3 and lol4 are labels

i wanted to change the text acordingly to the loop

take it as I have 4 labels


for count 1 to 4
if (count = 1)
i want lbl+1/2/3/4.text = lol2;
elseif
i want lbl+1/2/3/4.text = lol2;
 
I'm sorry for my poor command of english

I have those labels inside a table therefore I cannot combine them.

Those labels are called lbl1, lbl2, lbl3 and lbl4

I have a dataset containing some data I found

my loop looks like this

Dim starttime as Integer
Dim i As interger
Dim count as Integer = 900
Dim x as Integer =9

while count < 2401
startTime = result1.table("BookedPet").Rows(i).items("StartTime")
if startTime = count
lbl(x).text = "booked" <--- this is for lbl1 / lbl2 and lbl3
End If
x =x + 1
count = count +100
i =i +1
End While
 
you cannot access variables in this way!

what youre saying is, you have 4 variables, like these strings:

Dim s1, s2, s3, s4 As String



and then you want to make a loop and somehow access their in-code names via the loop:

VB.NET:
For i as Integer  = 1 to 4
  s[B][i][/B] = "hello"
Next


Can i just make one thing clear:
Ignoring reflection, no precompiled programming language has ever, nor will ever offer this functionality. You cannot use one variable value to reference the name of another variable in your code!!

Those variable names are lost when the code is compiled so they arent even called s1, s2, s3 any more..

in java its like

lbl+i = ...

in java, it's not like... sorry but it cannot be done.



What I suggest you do is use an array. in your case, an array of labels:

Dim myLabels(0 to 3) as Label
myLabels(0) = lbl1
myLabels(1) = lbl2
myLabels(2) = lbl3

myLabels(2) is the array(with index)
lbl3 is the name of the label in normal code..

both are pointers to an object in memory that is a label on screen. They point to the same place. Once can be accessed with a numeric indexer. One cannot.
 
Hi there, thanks for enlightening me, was too stressed out yesterday.

How do I actually store all the labels in 1 line via array?

I have like 10 labels spreading them out in 10 lines will be too long.

thanks.
 
Back
Top