As the label control is generally used as a label (!), you will probably know what text to use at design time, and will use the property window. However, to set the text in a label at runtime you use the following syntax:
Label1.Caption = Text
where Text is a string counting the text to be used. The code below sets Label1's text to Hello!
Label1.Caption = "Hello"
If you want to have more than one line of text in a label you have to set the text at runtime. Because labels uses a carriage return (Chr(10) + Chr(13)) you need to use vbCrLf as the return text, instead of Chr(vbKeyReturn) as you might think. The following example will put the text
An error occured
Please try again
into Label1.
Label1.Caption = "An Error occured" & vbCrLf
& "Please try again"
Comments