Android Question How to set a label.text with > 1 variable / Concatenate into 1 string?

tseyfarth

Member
Licensed User
Longtime User
Hello all,

I'm trying to set a Labels text with a First Name and a Last Name. The following line of code crashes the app.
B4X:
lbl_welcome.Text =FName + " " + LName

However if I use only the FName OR the LName then it works. But never with both or with the space in between
B4X:
lbl_welcome.Text =FName
lbl_welcome.Text =LName

lbl_welcome.Text =FName + " " + LName  <== crashes
lbl_welcome.Text =FName + LName <== crashes

Also, I tried to concatenate the two variables into a string, but that also crashes

B4X:
Dim s As String
s = FName + LName  <== crashes

So obviously I am doing something wrong when trying to concatenate these. Any help would be greatly appreciated!
Thank you!

Tim
 

emexes

Expert
Licensed User
Maybe also remove (trim) extraneous space when only one name:

B4X:
s = (FName & " " & LName).Trim
 
Last edited:
Upvote 0

tseyfarth

Member
Licensed User
Longtime User
Good to know Emexes. In my case, the variables had already been trimmed but this can also make it easier.

Thanks,
Tim
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Just another way (search for Smart String Literal):
B4X:
Dim s As String = $"${FName} ${LName}"$
'or
MyLabel.Text = $"${FName} ${LName}"$
'and so on
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…