Computer Programing 2
Computer Programing 2
Visual Basic.Net (VBNET) replaces VB6 in 2002 but Microsoft still provides some support for VB6.VB.NET is a fully
object- oriented programming language implemented in the .NET Framework. It was created to cater for the
development of the web as well as mobile applications. However, many developers still favor Visual Basic 6.0 over its
successor Visual Basic.NET.
We have already mentioned that VB.Net is part of .Net Framework and use for writing .Net applications. Therefore,
before discussing the available tools for running a VB.Net program let us understand how VB.Net relates to the .Net
Framework.
*Search on the Components of the .Net Framework and its job. (Provide a list on your paper and attach it on the last
page.)
Create a project
First, we’ll create a Visual application project. The project type comes with all the template files you’ll need, before
you’ve even added anything.
1. Open Visual Studio 2019.
2. On the start window, choose Create a new project.
3. On the Create a new project window, enter or type console in the search box. Next, choose Visual
Basic from the Language list, and then choose Windows from the Platform list. After you apply the language
and platform filters, choose the Console App (.NET Core) template, and then choose Next.
4. In the Configure your new project window, type or enter WhatIsYourName in the Project name box. Then,
choose Create.
2. Use the green Start button, or press F5 to build and run your first app.
3. When the console window opens, enter your name. Your console window should look similar to the
following screenshot:
Although the.NET Framework runs on the Windows operating system, there are some alternative versions that
work on other operating systems. Mono is an open-source version of the .NET Framework which includes a Visual
Basic compiler and runs on several operating systems, including various flavors of Linux and Mac OS. The most
recent version is VB 2012.
The stated purpose of Mono is not only to be able to run Microsoft .NET applications cross-platform, but also to
bring better development tools to Linux developers. Mono can be run on many operating systems including
Android, BSD, iOS, Linux, OS X, Windows, Solaris and UNIX.
A VB.Net program basically consists of the following parts −
Namespace declaration
A class or module
One or more procedures
Variables
The Main procedure
Statements & Expressions
Comments
Imports System
Module Module1
'This program will display Hello World
Sub Main()
Console.WriteLine("Hello World")
Console.ReadKey()
End Sub
End Module
When the above code is compiled and executed, it produces the following result − Hello, World!
The next line has a Module declaration, the module Module1. VB.Net is completely object oriented, so
every program must contain a module of a class that contains the data and procedures that your program
uses.
Classes or Modules generally would contain more than one procedure. Procedures contain the executable
code, or in other words, they define the behavior of the class. A procedure could be any of the following −
Function
Sub
Operator
Get
Set
AddHandler
RemoveHandler
RaiseEvent
The next line (‘This program) will be ignored by the compiler and it has been put to add additional
comments in the program.
The next line defines the Main procedure, which is the entry point for all VB.Net programs. The Main
procedure states what the module or class will do when executed.
The Main procedure specifies its behavior with the statement
Console.WriteLine("Hello World") WriteLine is a method of the Console class defined in
the System namespace. This statement causes the message "Hello, World!" to be displayed on the screen.
The last line Console.ReadKey() is for the VS.NET Users. This will prevent the screen from running and
closing quickly when the program is launched from Visual Studio .NET.
You can compile a VB.Net program by using the command line instead of the Visual Studio IDE −
Open a text editor and add the above mentioned code.
Save the file as helloworld.vb
Open the command prompt tool and go to the directory where you saved the file.
Type vbc helloworld.vb and press enter to compile your code.
If there are no errors in your code the command prompt will take you to the next line and would
generate helloworld.exe executable file.
Next, type helloworld to execute your program.
You will be able to see "Hello World" printed on the screen.
*Let’s Review. (Answer the following questions. Provide your answer in the blank.)
1. What language is the earliest programming language which uses the binary code to communicate with the
computer? _______________
2. It is a revolutionary platform that helps you to write the following types of applications – windows
applications, web applications and web services. ____________
3. It is used to include the System namespace in the program. ____________
4. It is a method of the Console class defined in the System namespace. ____________
5. To run the program you must ______________________________.