Let's perform the following steps to create and execute a VB.NET program.
Click Start then All Programs then Accessories then Notepad, as shown in Figure:
The Notepad window opens with a blank document.
Add the code, shown below, to the blank document:
In above program, a module is created to take input from user and then displaying respective output. The Imports statement is used to import the System namespace in the program. The Main() method is the main entry point from where the execution of VB.NET program starts.
Next, a string type variable, named msg, is declared and used to store a user entered message. The Console class and its method, Write(), ReadLine(), and WriteLine() are used to take input from user and display the respective output on the user's console window.
Select File then Save As.
The Save AS dialog box appears. In the Save As dialog box. you need to specify a name, type, and location for the document.
Select the location where you want to save the document, from the Address bar. In our case, we have selected the C:\Program Files\Microsoft Visual Studio 9.0\VC.
Type a name within double quotes for the document with the .vb extension. in the File name combo box. In our case, we have named it HellowWorld.vb, as shown in Figure:
Click the Save button to save the code.
Click Start then All Programs then Microsoft Visual Studio 2010 then Visual Studio Tools then Visual Studio Command Prompt to open the command prompt of Visual Studio.
Navigate to the directory location where the HelloWorld.vb file is saved.
Enter the following command in the Visual Studio Command Prompt window to compile the HelloWorld.vb file:
Enter the name of the EXE file in the Visual Studio Command Prompt windows that you want to execute. In our case, the name of the EXE file is HelloWorld.
Below fig. shows the output of HelloWorld.exe file:
Click Start then All Programs then Accessories then Notepad, as shown in Figure:
The Notepad window opens with a blank document.
Add the code, shown below, to the blank document:
Imports System
Module Sample
Sub Main()
dim msg as String
Console.Write("Enter Message => ")
msg=Console.ReadLine()
Console.WriteLine("You Entered " & msg)
End Sub
End Module
In above program, a module is created to take input from user and then displaying respective output. The Imports statement is used to import the System namespace in the program. The Main() method is the main entry point from where the execution of VB.NET program starts.
Next, a string type variable, named msg, is declared and used to store a user entered message. The Console class and its method, Write(), ReadLine(), and WriteLine() are used to take input from user and display the respective output on the user's console window.
Select File then Save As.
The Save AS dialog box appears. In the Save As dialog box. you need to specify a name, type, and location for the document.
Select the location where you want to save the document, from the Address bar. In our case, we have selected the C:\Program Files\Microsoft Visual Studio 9.0\VC.
Type a name within double quotes for the document with the .vb extension. in the File name combo box. In our case, we have named it HellowWorld.vb, as shown in Figure:
Click the Save button to save the code.
Click Start then All Programs then Microsoft Visual Studio 2010 then Visual Studio Tools then Visual Studio Command Prompt to open the command prompt of Visual Studio.
Navigate to the directory location where the HelloWorld.vb file is saved.
Enter the following command in the Visual Studio Command Prompt window to compile the HelloWorld.vb file:
vbc HelloWorld.vbThe preceding command generates an executable (EXE) file with respect to your VB code file. In our case. this file is HelloWorld.exe.
Enter the name of the EXE file in the Visual Studio Command Prompt windows that you want to execute. In our case, the name of the EXE file is HelloWorld.
Below fig. shows the output of HelloWorld.exe file:
0 comments:
Post a Comment