VB.NET Console Output



This article explains how to display output to the console in VB.NET.

There are two easy ways in VB.NET in which you can display output. Note, this article only covers Output onto the console window. There are other ways to display output, such as using a GUI or prompts. If you’re looking for a more user-friendly way, you can look those up instead. In this article though, we’ll cover both the Console.Write and the Console.WriteLine function.

Both functions are almost identical, in the sense that they display to console a string that is placed between their brackets. However, the WriteLine() automatically adds a newline character onto the string before displaying it. These new line characters are used by computers to understand that it must move to the next line. A computer is not a human after all.


Examples

Below are some examples that will demonstrate the difference. First up is Console.Write().

Module Module1
    Sub Main()

        Console.Write("Hello World")
        Console.Write("Hello World")
 
    End Sub
End Module
Hello WordHello World

Next is the Console.Writeline Function.

Module Module1
    Sub Main()

        Console.Write("Hello World")
        Console.Write("Hello World")
 
    End Sub
End Module
Hello World
Hello World

As you can see, the Writeline() function allows strings to be printed per line, where as Write() will output strings without any gap between them.


This marks the end of the VB.NET user input article. Any suggestions or contributions for CodersLegacy are more than welcome. Any questions can be asked in the comments section below.

Also see how to take input from console in VB.NET!

Leave a Reply

Your email address will not be published. Required fields are marked *