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

0

I created a method to form a Name that exists from some% program%, and give a numeric value to the Label property of this Text formed.

I just need to be able to do 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 Label that goes back 9 seconds of the variable Timer , and I want it to go back to 1 :

VarRetrocede = VarRetrocede - 1

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

VarNomeIncial.Text = VarRetrocede

Then Name of it will be the value of Label , from the moment it was combined.

But since it is a variable, you can not change the Text.

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

    
asked by anonymous 01.05.2018 / 22:59

1 answer

0

Try to get the control by its name:

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

If it does not work, use Control.Find

Dim referencia As Label = Me.Controls.Find("Index_3", False)
referencia.Text = 3
    
01.05.2018 / 23:21