How to Print Without a Line Feed in Visual Basic

Written by kevin walker
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Print Without a Line Feed in Visual Basic
(George Doyle/Stockbyte/Getty Images)

Visual Basic (VB) uses two different commands to print text to the screen, debugger and files. They are "Write" and "WriteLine," and their functionality differs only subtly. WriteLine will always go to the next line after it finishes printing (the equivalent of hitting the Enter key once in a word processor), while Write will not go to the next line after it finishes printing.

Skill level:
Moderately Easy

Other People Are Reading

Instructions

  1. 1

    Create a new project in Visual Basic by clicking "File" and "New Project." Select "ConsoleApplication."

  2. 2

    Paste the following within the project to print a single string to the debugger output without a new line feed:

    Debug.Write("This leaves the cursor on the same line after it prints. ")

    Debug.WriteLine("This is printing on the same line, but will end with a new line.")

    Debug.Write("This is on the next line.")

    If you run the program (click the green arrow), the following will be output into the debugger window:

    "This leaves the cursor on the same line after it prints. This is printing on the same line, but will end with a new line.

    This is on the next line."

  3. 3

    Paste the following to duplicate the same functionality, but this time printing to the user's console, rather than merely to the debugging window:

    Console.Write("This leaves the cursor on the same line after it prints. ")

    Console.WriteLine("This is printing on the same line, but will end with a new line.")

    Console.Write("This is on the next line.")

  4. 4

    Paste the following to write to a text file on the hard drive:

    Dim f = My.Computer.FileSystem.OpenTextFileWriter("c:\file.txt", True)

    f.Write("This leaves the cursor on the same line after it prints. ")

    f.WriteLine("This is printing on the same line, but will end with a new line.")

    f.Write("This is on the next line.")

Tips and warnings

  • As you can see, VB commands that print without a new line feed will usually be named "Write," and VB commands that print with a new line feed, so that the next printed string will appear on the next line, will be named "WriteLine."

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.