Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 23,421 times

Contents

Related Categories

Label Control - Setting the text

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"

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments