Changing label text programmatically

William Hunter

Active Member
Licensed User
Longtime User
I am trying to change label text programmatically. The label has been declared in Globals and initiated in Activity_Create. The code for the text change is in another sub. I have been able to make similar text changes with buttons, but can’t seem to do this with labels.

Any help would be appreciated. :sign0085:
 

klaus

Expert
Licensed User
Longtime User
It's the same as with Buttons.
Label1.Text = somestringvariable or
Label1.Text = "some text".
If the label is defined in a layout file you must NOT initialize it in Activity_Create !
Otherwise you are initiating a new instance and have no acces to the one difined in the layout file.

Best regards.
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
To change the label text it is just
B4X:
lb.Text = "One"
this can be done in the labels activity but not from another module.
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
Changing label text programatically

If the label is defined in a layout file you must NOT initialize it in Activity_Create !
Otherwise you are initiating a new instance and have no acces to the one defined in the layout file.
Thank you all for your response. Klaus correctly identified my error. I had initialized in Activity_Create. :signOops: All is now well.

Regards
 
Upvote 0

olivlaytchev

New Member
Licensed User
Longtime User
Hi, if I would like to have certain output (which is a combination of variables and text) from the label such as : 'result.Text = "Your annual return in % is: " annualReturn " and your investment will be returned in "years" years."'.
How do I correctly concatenate the variables' value with the text?? Help is appreciated
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Are you meaning this?
B4X:
result.Text = "Your annual return in % is: " & annualReturn &" and your investment will be returned in " &years &" years."'.

udg
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…