Tag Archives: vbCrlf

How to do Multi-Line Messageboxes and Inputboxes in VB 6.0 and in VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.67 out of 5)
 

How to do Multiple Lined Messages (Input and Messagebox) is a very common question. Unfortunately the Message Functions do not have a native multi-lined option. But there is a simple workaround to create messages on different/separate lines. It is a little constant called: vbNewLine which is evidentially a brother to the vbCrLf constant.

Public Const vbNewLine As String = vbCrLf

Public Const vbCrLf As String = vbCrLf

These constants are basically the same as combining Chr(13) and Chr(10) characters which maps to the Carriage Return – Line Feed. Using the constants is very simple. Just add the constant outside the string that you want to start a new line at. Below is basic examples of using them…


        'Create a new string to display.
        Dim myString As String

        myString = "I want a Multi-Lined Message!"

Now that there is a string to use, simply add the vbNewline constant as so…

        myString = "I want a Multi-Lined Message!" & vbNewLine & vbNewLine & "This message is under the first!"
        MsgBox(myString)

The “myString” variable should now display as a multiline string.

The multilined messagebox.


That’s all you have to do! The vbNewline Constant (vbCrlf also) is all you need to do to make most multi-lined messages. This is a simply fix and should work just fine for most messagebox/inputbox messages and such.

Remember that these constants are available in ALL versions of Visual Basic. VB 6.0 through to VB.NET 2008, VB.NET 2010, and VB 2013. Have Fun!

Jason