How to use \n new line in VB msgbox() ...?

469.1k Views Asked by At

What is the alternative to \n (for new line) in a MsgBox()?

17

There are 17 best solutions below

5
Fun Mun Pieng On BEST ANSWER
  • for VB: vbCrLf or vbNewLine
  • for VB.NET: Environment.NewLine or vbCrLf or Constants.vbCrLf

Info on VB.NET new line: http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx

The info for Environment.NewLine came from Cody Gray and J Vermeire

1
Jens On
0
Hans Olsson On

Add a vbNewLine as:

"text1" & vbNewLine & "text2"
3
Pranay Rana On

These are the character sequences to create a new line:

  • vbCr is the carriage return (return to line beginning),

  • vbLf is the line feed (go to next line)

  • vbCrLf is the carriage return / line feed (similar to pressing Enter)

I prefer vbNewLine as it is system independent (vbCrLf may not be a true new line on some systems)

1
Developer On

Try using vbcrlf for a newline

msgbox "This is how" & vbcrlf & "to get a new line"
0
SQAHero On

Use the command "vbNewLine"

Example

Hello & vbNewLine & "World"

will show up as Hello on one line and World on another

0
slagou On

An alternative to Environment.NewLine is to use :

Regex.Unescape("\n\tHello World\n")

from System.Text.RegularExpressions

This allows you to escape Text without Concatenating strings as you can in C#, C, java

0
Harish Narayanaswamy On

The message box must end with a text and not with a variable

0
D_T On

You can use carriage return character (Chr(13)), a linefeed character (Chr(10)) also like

MsgBox "Message Name: " & objSymbol1.Name & Chr(13) & "Value of BIT-1: " & (myMessage1.Data(1)) & Chr(13) & "MessageCount: " & ReceiveMessages.Count
0
user2885689 On
Module MyHelpers
    <Extension()>
    Public Function UnEscape(ByVal aString As String) As String

       Return Regex.Unescape(aString)

    End Function
End Module

Usage:

console.writeline("Ciao!\n".unEscape)
1
user3174223 On

msgbox("your text here" & Environment.NewLine & "more text") is the easist way. no point in making your code harder or more ocmplicated than you need it to be...

0
Bertrand On

On my side I created a sub MyMsgBox replacing \n in the prompt by ControlChars.NewLine

0
user6225788 On

The correct format is :

"text1" + vbNewLine + "text2"
3
Ariel Gabizon On

A lot of the stuff above didn't work for me. What did end up working is

Chr(13)
0
pietro smusi On

This work for me: MessageBox.Show("YourString" & vbcrlf & "YourNewLineString")

0
zdlk On

You can use Environment.NewLine OR vbCrLF OR vbNewLine

MsgBox($"Hi!{Environment.NewLine}I'M HERE")
0
user13960527 On

do not forget to set the Multiline property to true in textbox