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

Vb6NewlineMsgbox

Vb6 Problem Overview


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

Vb6 Solutions


Solution 1 - Vb6

  • 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

Solution 2 - Vb6

Try using vbcrlf for a newline

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

Solution 3 - Vb6

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)

Solution 4 - Vb6

Solution 5 - Vb6

Add a vbNewLine as:

"text1" & vbNewLine & "text2"

Solution 6 - Vb6

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

Solution 7 - Vb6

The correct format is :

"text1" + vbNewLine + "text2"

Solution 8 - Vb6

Use the command "vbNewLine"

Example

Hello & vbNewLine & "World"

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

Solution 9 - Vb6

You can use Environment.NewLine OR vbCrLF OR vbNewLine

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

Solution 10 - Vb6

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

Solution 11 - Vb6

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)

Solution 12 - Vb6

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

Solution 13 - Vb6

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

Chr(13)

Solution 14 - Vb6

msgbox "This is the first line" & vbcrlf & "and this is the second line"

or in .NET msgbox "This is the first line" & Environment.NewLine & "and this is the second line"

Solution 15 - Vb6

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

Solution 16 - Vb6

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...

Solution 17 - Vb6

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

Solution 18 - Vb6

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWasim A.View Question on Stackoverflow
Solution 1 - Vb6Fun Mun PiengView Answer on Stackoverflow
Solution 2 - Vb6DeveloperView Answer on Stackoverflow
Solution 3 - Vb6Pranay RanaView Answer on Stackoverflow
Solution 4 - Vb6JensView Answer on Stackoverflow
Solution 5 - Vb6Hans OlssonView Answer on Stackoverflow
Solution 6 - Vb6slagouView Answer on Stackoverflow
Solution 7 - Vb6user6225788View Answer on Stackoverflow
Solution 8 - Vb6SQAHeroView Answer on Stackoverflow
Solution 9 - Vb6zdlkView Answer on Stackoverflow
Solution 10 - Vb6D_TView Answer on Stackoverflow
Solution 11 - Vb6user2885689View Answer on Stackoverflow
Solution 12 - Vb6BertrandView Answer on Stackoverflow
Solution 13 - Vb6Ariel GabizonView Answer on Stackoverflow
Solution 14 - Vb6Martin ReicherView Answer on Stackoverflow
Solution 15 - Vb6user13960527View Answer on Stackoverflow
Solution 16 - Vb6user3174223View Answer on Stackoverflow
Solution 17 - Vb6pietro smusiView Answer on Stackoverflow
Solution 18 - Vb6Harish NarayanaswamyView Answer on Stackoverflow