How to Add a New Line in Visual Basic

104 9
    • 1). Open your Visual Studio application and load the Visual Basic project. After the project loads, right-click the form or Web page and select "View Code."

    • 2). Define a string variable. Since a new line character is a part of a string, a string variable is first needed. The code below creates a string variable and assigns it a sentence:
      Dim strMyString as String
      strMyString = "Hello World."

    • 3). Add a new line character to the string. Visual Basic has an internal constant that is used for the CRLF character. The code below illustrates how to use vbCRLF:
      strMyString = strMyString & vbCRLF

    • 4). Add to the string variable. In this example, another sentences is added to the strMyString variable. When the string prints, the "Hello World" section is displayed above the "This is my first string" sentence. The following code adds to the string:
      strMyString = strMyString "This is my first string."

    • 5). Print the output to the debugger window. The following statement allows you to review the results in the debugger window in Visual Studio:
      Print strMyString
      The results returned by the application are:
      Hello World
      This is my first string.

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.