473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Using variable names to change labels

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
3 2267
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jens Thiede | last post by:
I found the querk in my code: a = ; b = a; b.append(4); b == ; # As it should. a == ; # - Why? One would think that b is a referance to a - however I know it's not.
6
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
18
by: Tinus | last post by:
Hello, I want to do the following: I have 10 labels on my form, called Label0 to Label9. Now I want to change the Text property of all the labels at once, e.g.: for (int i = 0; i < 10; i++)...
2
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to...
5
by: glenn | last post by:
Hi folks, The problem I have is that a query string works if hard-coded but if I pass a variable to it, it does not work as shown here. This works: querystring="SELECT * FROM USERS WHERE...
0
by: napolpie | last post by:
DISCUSSION IN USER nappie writes: Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by...
1
by: viceyo | last post by:
Hi! I'm new to Javascript and I'm trying to write a script in which I need to use diferent variable names. The names are used from here: <img border="0" alt="Visit W3Schools!"...
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.