How to use a variable that represents the name of a label to change its value?

Asked

Viewed 551 times

0

I created a method to form a Name that there is any Label of the program, and give a numerical value to the property Text of that Label graduate.

And I just need to be able to do it like this:

Variavel = "NameDaLabel"
Variavel.Text = "Valor"

I have the following variables:

Dim VarRetrocede As Integer  = 9
Dim VarNomeInicial As String = "Index_"

I have a code in a Timer which returns the 9 second value of the variable VarRetrocede, and I want you to come back until 1:

VarRetrocede = VarRetrocede - 1

And until that value reaches 1 has a code running at the same time, which combines the VarNomeInicial and VarRetrocede to form a Name of some Label, because all the Name of Label are in this pattern: "Index_2" and some number, and the value of Text of Label are equal to the number. And while the code forms a Name, a numerical value is given to Label which was arranged at the time:

VarNomeIncial.Text = VarRetrocede

Then the Text of it will be the value of VarRetrocede, the moment she was combined.

But as it is a variable can’t change Text.

I really need this, is it possible? I will be very grateful for any answer.

1 answer

0


Try to take control by his name:

Dim referencia As Label = DirectCast(Me.Controls("Index_3"), Label)
referencia.Text = 3

If it doesn’t work, use Control.Find

Dim referencia As Label = Me.Controls.Find("Index_3", False)
referencia.Text = 3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.