How to Continue Code to the Next Line in Msgbox Vba
17 Answers 17
Stevoisiak
21.3k 25 gold badges 118 silver badges 208 bronze badges
answered Mar 1, 2011 at 8:36
Fun Mun PiengFun Mun Pieng
6,553 3 gold badges 27 silver badges 30 bronze badges
5
Try using vbcrlf
for a newline
msgbox "This is how" & vbcrlf & "to get a new line"
Stevoisiak
21.3k 25 gold badges 118 silver badges 208 bronze badges
answered Mar 1, 2011 at 8:36
DeveloperDeveloper
8,302 38 gold badges 124 silver badges 233 bronze badges
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♦
234k 50 gold badges 482 silver badges 561 bronze badges
answered Mar 1, 2011 at 8:35
Pranay RanaPranay Rana
172k 35 gold badges 236 silver badges 261 bronze badges
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 asvbCrLf
. 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♦
234k 50 gold badges 482 silver badges 561 bronze badges
answered Mar 1, 2011 at 8:34
JensJens
3,221 2 gold badges 24 silver badges 41 bronze badges
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 OlssonHans Olsson
53.4k 14 gold badges 91 silver badges 113 bronze badges
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
slagouslagou
308 5 silver badges 10 bronze badges
The correct format is :
"text1" + vbNewLine + "text2"
Paul Roub
36.1k 27 gold badges 80 silver badges 88 bronze badges
answered Apr 19, 2016 at 15:37
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
SQAHeroSQAHero
41 1 silver badge 3 bronze badges
You can use Environment.NewLine OR vbCrLF OR vbNewLine
MsgBox($"Hi!{Environment.NewLine}I'M HERE")
answered Oct 1, 2021 at 13:13
zdlkzdlk
21 4 bronze badges
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
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
On my side I created a sub MyMsgBox replacing \n in the prompt by ControlChars.NewLine
answered Jul 7, 2015 at 13:33
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 GabizonAriel Gabizon
2,521 2 gold badges 16 silver badges 21 bronze badges
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
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
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
The message box must end with a text and not with a variable
answered Mar 31, 2013 at 12:52
Source: https://stackoverflow.com/questions/5152042/how-to-use-n-new-line-in-vb-msgbox
Do not use
vbCrLf
for VB.NET code! That's only there for compatibility with ported VB 6 applications. You should be usingEnvironment.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