|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using variable names to change labelsThis 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 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. Show quoteHide quote "Jarry" <HarryandJa***@gmail.com> wrote in message news:1163100362.315640.48890@m73g2000cwd.googlegroups.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 > Marina Levit [MVP] wrote:
> You would have to find the control by name. I don't know if this is a web I considered that, and, now you mantion it, it does seem to be the best> 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. > 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... 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). Show quoteHide quote "Jarry" <HarryandJa***@gmail.com> wrote in message news:1163101550.619757.276920@f16g2000cwb.googlegroups.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... >
VB Controls In VB2005
update database through SQL script difference between dataAdapter.InsertCommand/dataAdapter.SelectCom remove xml file root tag Get the value of a cell when row changes in DataGridView how to capture enter key without affrecting copy paste kcust keys max length for tooltip add xml validation schema in the xml file remove xml file namespace attribute Creating a Sub/Function routine |
|||||||||||||||||||||||