How to Continue Code to the Next Line in Msgbox Vba

17 Answers 17

Stevoisiak's user avatar

Stevoisiak

21.3k 25 gold badges 118 silver badges 208 bronze badges

answered Mar 1, 2011 at 8:36

Fun Mun Pieng's user avatar

5

  • Do not use vbCrLf for VB.NET code! That's only there for compatibility with ported VB 6 applications. You should be using Environment.NewLine instead, as suggested in J. Vermeire's answer.

    Mar 1, 2011 at 8:55

  • I agree with you that Environment.NewLine should be used, but because it is cross platform. It returns \r\n for Window, but only \n for unix/linux based platforms.

    Mar 2, 2011 at 5:00

  • Yes, that's a very good reason to use it. Considering that alternative implementations of the CLR (like Mono) support VB.NET, it's a good idea to write code with an eye towards platform independence. Beyond that, adopting standard .NET Framework idioms, rather than holdovers for backwards compatibility purposes, is always a good idea. The biggest mistake any VB.NET programmer will make is assuming it's the same language as VB 6. It's emphatically not! The true object-orientation is only scratching the surface of the differences. Pretending otherwise is doing yourself an injustice.

    Mar 2, 2011 at 5:39

  • Down vote because it doesn't work for me. Calling EditPoint.Insert(vbNewLine) in a VB macro inserts \r\n. vbLf is the correct answer to the asked question.

    Nov 27, 2012 at 18:16

  • I just declared a public string called n... just for convenience. (Public n As String = Environment.NewLine)

    Apr 13, 2021 at 21:26

Try using vbcrlf for a newline

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

Stevoisiak's user avatar

Stevoisiak

21.3k 25 gold badges 118 silver badges 208 bronze badges

answered Mar 1, 2011 at 8:36

Developer's user avatar

1

  • The example is appreciated because I don't work with VB and didn't know the concatenation format. They are evidently not interpreted within double quotes.

    Aug 14, 2020 at 21:46

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)

Cody Gray's user avatar

Cody Gray

234k 50 gold badges 482 silver badges 561 bronze badges

answered Mar 1, 2011 at 8:35

Pranay Rana's user avatar

3

  • @Andrew - during my college days when i do programming in vb

    Mar 1, 2011 at 8:37

  • Theoretically, I suppose you're right. But in every implementation that I've seen, vbNewLine is simply defined as vbCrLf. There isn't any difference.

    Mar 1, 2011 at 8:42

  • I wouldn't change anything. I agree with you the way it is. I think vbNewLine more clearly expresses your intent. It's obviously been designed to insert a new line. I was just providing auxiliary commentary. "Under the hood", they do the same thing. Implementation details like that shouldn't leak into your code.

    Mar 1, 2011 at 8:46

Cody Gray's user avatar

Cody Gray

234k 50 gold badges 482 silver badges 561 bronze badges

answered Mar 1, 2011 at 8:34

Jens's user avatar

1

  • This is the correct solution for VB.NET. Skip the vbCrLf/vbNewLine nonsense unless you're using VB 6.

    Mar 1, 2011 at 8:42

Add a vbNewLine as:

              "text1" & vbNewLine & "text2"                          

answered Mar 1, 2011 at 8:35

Hans Olsson's user avatar

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

answered Jan 22, 2013 at 21:05

slagou's user avatar

The correct format is :

              "text1" + vbNewLine + "text2"                          

Paul Roub's user avatar

Paul Roub

36.1k 27 gold badges 80 silver badges 88 bronze badges

answered Apr 19, 2016 at 15:37

user6225788's user avatar

Use the command "vbNewLine"

Example

              Hello & vbNewLine & "World"                          

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

answered Apr 17, 2012 at 5:18

SQAHero's user avatar

You can use Environment.NewLine OR vbCrLF OR vbNewLine

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

answered Oct 1, 2021 at 13:13

zdlk's user avatar

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                          

answered Mar 20, 2014 at 18:26

D_T's user avatar

              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)                          

answered Aug 22, 2014 at 15:26

user2885689's user avatar

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

answered Jul 7, 2015 at 13:33

Bertrand's user avatar

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

                Chr(13)                              

answered Mar 11, 2017 at 18:55

Ariel Gabizon's user avatar

3

  • Shouldn't it be Chr(10)?

    Apr 29, 2020 at 18:52

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

answered Feb 8 at 21:04

user13960527's user avatar

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

answered Nov 18, 2014 at 16:45

user3174223's user avatar

1

  • Your answer (Environment.NewLine) was already given 3 years ago and is the highest voted answer. This is more like commentary. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post.

    Nov 18, 2014 at 17:07

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

answered Sep 26, 2018 at 14:26

pietro smusi's user avatar

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

answered Mar 31, 2013 at 12:52

Harish Narayanaswamy's user avatar

martinezheen1998.blogspot.com

Source: https://stackoverflow.com/questions/5152042/how-to-use-n-new-line-in-vb-msgbox

0 Response to "How to Continue Code to the Next Line in Msgbox Vba"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel