Module 4
Module 4
When the above code is compiled and executed, it produces following result:
VB.NET CLASS!
VB.NET Sample cont.
• The first line of the program Imports System is used to include the
System namespace in the program.
• 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 etc
VB.NET Sample cont.
• 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(“VB.NET CLASS")
• WriteLine is a method of the Console class defined in the System
namespace. This statement causes the message
• “VB.NET CLASS!" to be displayed on the screen.
Visual Basic Standard Modules
• 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.
• A module is a global or public object where you can place program code
such as variables, functions & procedures that can be seen by all code in
the entire project.
• The key here is Global code!
• Suppose you wanted to write code that can manipulate or operate on
various forms & controls. How can you do this? Since every code you
write for a control or form is only visible within the form? Where would
you place the code? The answer is the Module!
Visual Basic Standard Modules cont.
• The Module has the following characteristics:
• Modules contain a method named Sub Main() that can be used as the starting
point of the application. Note this applies to both Console Applications and
Windows Applications.
• Modules contain variable declarations, functions & procedures or source code
ONLY! No forms!
• Modules are a good place to put program code that may be common to several
forms or other modules.
• Modules contain variables & Methods.
• Modules are like forms but without the visual!
• When you create a Console Application, Visual Basic automatically
creates a Module where you can begin entering your code:
Code Editor for Console
Application
• For a Console Application, the code editor in invoked immediately to
allow you to enter code in the Module.
• Simply begin entering code in the Module Document.
• The Code Editor screen contains two drop-down list boxes, one for
the Object you are coding and the other for the Methods & Event-
Procedures associated with the object:
Code Editor for Console
Application cont.
How Visual Basic Organizes Your
Program or Application Files
• When you create a VB program a Folder is automatically
created in you computer which contains the files of the
program.
• A Visual Basics application is called a Solution. The Solution
is composed of one or more Project.
• The table below lists several important files and their file
extensions:
How Visual Basic Organizes Your Program or
Application Files cont.
File Explanation Example
Extension
.sln Solution – File that holds information VideoManagement.sln
about all the projects in the application