Console Applications August 1, 2008
Posted by tuse in : Console , add a commentVisual Studio lets you develop Console Applications as well. Console Applications are command-line applications similar to C or Java programs. These applications allow you to take input, display characters on a DOS window.
In order to develop a Console Application, start Visual Studio, point to New Project and select ‘Console Application’.
The System.Console namespace supports the creation of Console Applications.
As with C and Java, the program execution begins with the Sub Main() - the entry point of the program.
Module Module1
Sub Main()
Dim nm As String
System.Console.Write("Enter your name: ")
nm = System.Console.ReadLine()
System.Console.WriteLine("Your name is: " & nm)
System.Console.ReadLine()
End Sub
End Module
This simple program accepts a string from the user and displays it on the console. As you can see, the code is quite similar to a program written in Java. In order to execute this program, press F5/ Debug->Start.
A DOS window pops up asking you to enter your name. This is due to the ‘System.Console.Write()’‘ method.
Similarly, ‘System.Console.ReadLine()’ is used to read a line from the console. The final ‘System.Console.ReadLine()’ is like the getch() used in C programs so that the console ‘waits’ for a keypress before termination.
