Library tutorials & articles

Label Control

Setting the text

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

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of Label Control.

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...
AddThis

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

Want to stay in touch with what's going on? Follow us on twitter!