In Visual Basic 2015, you can build console application besides Windows Form Applications. To start creating a console application, start Visual Basic 2015 and choose Console Application in the new project window, as shown in Figure 37.1 below:
Retain the name as Console Application 1 or change it to the name of your choice. Now, click on Console Application to bring up the code window, as shown in Figure 37.2 below:
The console code window comprises modules, where the main module is module 1. You an add other modules by clicking on Project on the menu bar and click Add Module, as shown in Figure 37.3 below:
To start writing code for the console application, type your code in between Sub Main() and End sub, as shown below:
Sub Main ( ) Your code End Sub
The following program will display a message " Welcome to Visual Basic 2015 Console Programming". The function to display a message box is MsgBox(). Enter the code as follows:
Run the program and the output is as shown in Figure 37.5 below:
You can write a looping program using the Do Until....Loop structure, as shown below:
Sub Main() Dim x As Single Do Until x >10 x = x + 1 Loop MsgBox("The value of x is"& x) End Sub
The output is
The value of x is 11
Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy