variable label when setting the text property

J

Johan

Hello,

Is it possible in vb.net to do the following

normal procedure for setting a label
label.text = " blablabla"

What I would like to do is the same but where the label is a variable

eg.
dim varlabel as new label()
varlabel.text = "123"
where the content of varlabel is a label wich is on the form.

Is this possible ? (probally it is, since in c++ it is not a problem)

Thanks in advance,
Johan Van Loo
 
H

Herfried K. Wagner [MVP]

* "Johan @ pandora.Be said:
Is it possible in vb.net to do the following

normal procedure for setting a label
label.text = " blablabla"

What I would like to do is the same but where the label is a variable

eg.
dim varlabel as new label()
varlabel.text = "123"
where the content of varlabel is a label wich is on the form.

Is this possible ? (probally it is, since in c++ it is not a problem)

Yes, it's possible, but I am not sure if I understand your question.
You will have to add the new label to the form's 'Controls' collection:

\\\
Dim lbl As New Label()
lbl.Text = ...
Me.Controls.Add(lbl)
///
 
M

mmartin

Johan @ pandora.Be said:
Hello,

Is it possible in vb.net to do the following

normal procedure for setting a label
label.text = " blablabla"

What I would like to do is the same but where the label is a variable

eg.
dim varlabel as new label()
varlabel.text = "123"
where the content of varlabel is a label wich is on the form.

Is this possible ? (probally it is, since in c++ it is not a problem)

Thanks in advance,
Johan Van Loo

I think you mean something like...

Dim varlabel as New Label()
Dim ctrl As Control

For Each ctrl In Me.Controls
If ctrl.GetType.Equals(label.GetType) Then
label = ctrl
label.Text = label.Text.ToUpper ' or whatever you want to do with
it... 123 or what not...
End If
Next
 
J

Johan

Thanks,

That is ideed what i want to do, but your sollution is using an if
statement. It loops over de controls in the form.... I would like to do the
other thing , (skip the if statement so everything goes much faster).
If i could just loop over the recordset and set the labels immediately
without the if statement that would be nice :)

Thank,
Johan Van Loo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top