Change Multi-Line Label

So I found this tid-bit → Multiple Label Lines Hoping it would answer my question and solve the problem.

I have a label that is set for multiple line and index 0 = “Start” Index 1 = “Lunch”

Using this code:
Dim tempLabel() As String = Split(Label1.text, EndOfLine) tempLabel(1) = "Replacing the second line." Label1.text = Join(tempLabel, EndOfLine)

I adapted and failed with this code…
strTmpLbl = Split( lblBtnStartEndLunch.Value.ToText, EndOfLine ) strTmpLbl( 0 ) = "Start" lblBtnStartEndLunch.Value.ToText = Join( strTmpLbl, EndOfLine )

I get a Syntax Error and not other information to help decipher what I did wrong…

Does this make sense to you?

When I try the lblBtnStartEndLunch.Text I still get a Syntax Error. I followed the example but used what I know to work for other instances when I assign a value to a Label. But those are usually just a single line or word.

The .Text option doesn’t appear either. And lblBtnStartEndLunch is the name of the object.

It’s not your only mistake.

Do you actually dim (or var) strTmpLbl? And as what? A String? Or an Array of Strings? Because you try to stuff an array of strings into it (the result of the Split method).

the above code is not mine, I got it from here → Multiple Label Lines - #3 by Bob_Manning Bob Coleman posted it. I copied it and changed the variable to meet my needs and… there is a Syntax error.

← This is my adaptation…

Again: where is your Dim statement? Do you know what Dim does? If so, why do you think you can leave it out?

I have the variable declared earlier, I didn’t include it in my example.

Var strTmpLbl() As String - It’s declared earlier in the code stream.

what control is it ? a button ?
then try lblBtnStartEndLunch.caption =

Labels don’t have a Value property. Seems like your code should be

strTmpLbl = Split( lblBtnStartEndLunch.Text, EndOfLine )
strTmpLbl(0) = "Start"
lblBtnStartEndLunch.Text = Join(strTmpLbl, EndOfLine)

Well, in the first place that thread is ridiculous. Getting the text, try to split it, try to replace one of the array elements…

Just have an array already as a property of the window or a subclass of the label, add a method ReplaceLine(NewText As String, Line as Integer) and in there replace the item and then change the Caption using the Array.Join function

Label Value in code

Label Value in code2

No, it’s a Label that has the property Multiline enabled, I want to change one line of the Label to reflect what is happening in the application at the time.

You must be on one of those weird transitional releases between 2019 and 2020r1 where everything was messed up. They reverted back to sanity in 2020r2.

Replace .Text with .Value and it should work.

Edit: if you type in .Text it should also work. You won’t get autocomplete and you’ll get a deprecation warning in Analyze Project, but it should still compile and run. And you’ll be future-ready should you decide to upgrade to the current release.

Edit2: The property was .Text for the last 20 years. In 2019r2 they made the ill-advised decision to change it to .Value. In 2020r2 they finally changed it back.

1 Like