VB.net Labels: Changing Caption on Multiple Lines

  • Thread starter Thread starter Pauly Man
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around how to change the caption of a label to display multiple lines in VB.NET, contrasting it with previous versions like VB6. Participants explore various methods to achieve line breaks in label text.

Discussion Character

  • Technical explanation
  • Exploratory
  • Homework-related

Main Points Raised

  • One participant describes how to concatenate strings with line breaks in VB6 using Chr(13) and Chr(10), noting that this approach does not work in VB.NET.
  • Another participant suggests using "\n" as a potential solution, humorously noting the shift in conventions.
  • A participant reports that Chr(10) works for line breaks in VB.NET, while Chr(13) does not.
  • It is proposed that using the constant vbCrLf is the ideal way to create new text lines in VB.NET.
  • One participant confirms that vbCrLf works and expresses curiosity about finding constants in the help files.
  • Another participant provides guidance on where to find information about constants in VB6 and speculates on similar resources for VB.NET.
  • A new participant shares their experience of finding the relevant information in the Visual Basic language reference for VB.NET.

Areas of Agreement / Disagreement

Participants generally agree on the use of vbCrLf for line breaks in VB.NET, but there is no consensus on the best way to find documentation for these constants, as experiences and resources vary.

Contextual Notes

Some participants mention limitations in the help files regarding constants, and there is uncertainty about the exact location of this information in VB.NET documentation.

Pauly Man
Messages
129
Reaction score
0
In VB6 and earlier if you wanted to have your program change the caption of a label you would code something like this:

Code:
dim L,L1,L2 as string
L1 = "Hello There!"
L2 = "I am Paul."
L = L1 & Chr(13) & Chr(13) & L2
lblMyLabel.Caption = L

The above code would create a label message on two lines as follows:

Code:
Hello There!
I am Paul.

Now this doesn't work in VB.net. (I know that .caption is replaced with .text). VB.net completely ignores the Chr() keyword. Does anyone else know how the above can be done now?
 
Computer science news on Phys.org
Have you tried "\n"? Maybe Microsoft has switched to the standard convention. (ha, ha, I know)
 
I tried the "\n" and it doesn't work. :frown:
 
Sorted it. FOr some reason, Chr(13) is no longer recognised as a line break, but Chr(10) works.
 
chr(13) is a carridge return, chr(10) is a linefeed. You should ideally use both when making a new text line.
Try using the constant vbCrLf instead.
i.e. L = L1 & vbCrLf & L2
 
The vbCrLf works. And I can see where it gets its name, ie. vbCreateLinefeed. But I can't find any of these constants in the help files, so how do you find out about them?
 
I thought it would work. :smile:

For the vbCRLF constant:
It's mentioned in the "Working with Text Boxes" topic.

For constants in general:
In VB6, look in the Help-Contents-VisualBasicDocumentation-Reference-Constants, then there's several items that each have many subitems. It's in there somewhere.

I'm not sure where it is located for vb.net help, but I would assume it's similar. You might try searching the help for "reserved words", "constant", or something. Maybe even searching "vb" will help since they all (most) start with vb for visualbasic.

And I can see where it gets its name, ie. vbCreateLinefeed.
Acutally, it stands for "CarridgeReturn-LineFeed".
A "CarridgeReturn" is originally from the typewriter. The metal bar across the top is called a carridge return. When you push it to the right (to begin typing at the left of the page) it rolled the typewriter "carridge" up one line as it "returned" from the right. It's been used for computers ever since they were connected to a CRT and keyboard.
(edit: Maybe since they were connected to the first printers instead of CRTs.)
 
Hello guys.
I just ran into your post trying to find out how to put line feed into my label box for class.
I referenced back and found it under Visual Basic language Reference> Print and Display Constants in VB.NET.
Hope this helps. I just stared VB.NET class this week.
~Ocilimond
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
2
Views
12K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 33 ·
2
Replies
33
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K