By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

Using variable names to change labels

P: n/a
This may sound really obvious, but is there a way to change the text of
different certain label depending on an integer? For example, here is
the long hand (using the default label1, label2 etc) :
Dim myInteger as integer = 15
Select Case myInteger
Case 1
label1.text = "This was changed"
Case 2
label2.text = "This was changed"
Case 3 ...
End Select
There must be a better way - I was thinking something along the lines
of the eval() statement in javascript etc? Or something completly
different?

Thanks

Nov 9 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You would have to find the control by name. I don't know if this is a web
form or a winforms, but you can typically do it either way.

A more reliable solution is to put them in a label array, and index into the
array to get the appropriate one.

"Jarry" <Ha***********@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
This may sound really obvious, but is there a way to change the text of
different certain label depending on an integer? For example, here is
the long hand (using the default label1, label2 etc) :
Dim myInteger as integer = 15
Select Case myInteger
Case 1
label1.text = "This was changed"
Case 2
label2.text = "This was changed"
Case 3 ...
End Select
There must be a better way - I was thinking something along the lines
of the eval() statement in javascript etc? Or something completly
different?

Thanks

Nov 9 '06 #2

P: n/a

Marina Levit [MVP] wrote:
You would have to find the control by name. I don't know if this is a web
form or a winforms, but you can typically do it either way.

A more reliable solution is to put them in a label array, and index into the
array to get the appropriate one.
I considered that, and, now you mantion it, it does seem to be the best
option. Are there any more? Also, is it possible to define variables
using another variable:

For x = 1 to 20
Dim (myVar + x) as string
Next x

for instance? I have a huge array, and it might help...

Nov 9 '06 #3

P: n/a
No, you cannot do anything like what you have there. The compiler can't
make sense of that.

I would say either array, or use the methods available to find the label by
name on the page (i'm assuming asp.net from the way you've been talking).

"Jarry" <Ha***********@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
>
Marina Levit [MVP] wrote:
>You would have to find the control by name. I don't know if this is a web
form or a winforms, but you can typically do it either way.

A more reliable solution is to put them in a label array, and index into
the
array to get the appropriate one.

I considered that, and, now you mantion it, it does seem to be the best
option. Are there any more? Also, is it possible to define variables
using another variable:

For x = 1 to 20
Dim (myVar + x) as string
Next x

for instance? I have a huge array, and it might help...

Nov 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.