Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

4.

INTRODUCTION TO VISUAL BASIC-6


PROGRAM LANGUAGE
Visual Basic is the favorite programming environment of many programmers.
When visual basic first appeared, it created a revolution in windows programming,
and that revolution continues to this day. Never before had windows programming
been so easy-just build the program you want, right before your eyes, and then run it.
Visual Basic (VB) is the third-generation event-driven programming language and
integrated development environment (IDE) from Microsoft for its COM programming
model. VB is also considered a relatively easy to learn and use programming
language, because of its graphical development features and BASIC heritage.

Visual Basic was derived from BASIC and enables the rapid application development
(RAD) of graphical user interface (GUI) applications, access to databases using Data
Access Objects, Remote Data Objects, or ActiveX Data Objects, and creation of
ActiveX controls and objects.

4.1 Creating a project in Visual Basic-6:


Figure 4.1 shows some of the project types that visual basic-6 supports:
4.1.1 Standard Windows EXE programs
4.1.2 ActiveX EXE files
4.1.3 Active X DLLs
4.1.4 ActiveX controls
4.1.5 Programs Written by the Visual
Basic Application Wizards
4.1.6 Data projects
4.1.7 IIS (the Microsoft Internet
Information Server) applications
4.1.8 Visual Basic add-ins
4.1.9 ActiveX document DLLs Figure No 4.1 Startup page of Visual
Basic-6
4.1.10
ActiveX document EXE files
4.1.11 DHTML applications
CHAPTER 4

4.1.12 VB Professional Edition controls

4.2 The part of a Visual Basic Project:


Standard Visual Basic projects usually contain just three types of items: global
items, forms, and modules as outlined in figure no 4.2.
4.2.1 Forms:
They are the templates you base windows on.
4.2.2 Modules:
Modules are collection of code and data that function something like objects in
object-oriented programming. The point behind modules is to enclose procedures and
data in a way that hides them from the rest of the program.
4.2.3 Global Items:
Global items are accessible to all modules and forms in a project, and you
declare them with the ‘Public’ keyword. However, Microsoft recommends that you
keep the number of global items to an absolute minimum and, in fact, suggests their
use only when you need to communicate between forms. One reason to avoid global
Visual Basic Project variables is their accessibility from
anywhere in the program; while you’re
Global Items
Form working with a global variable in one
Form Form Form part of a program, another part of the
Module program might be busy changing that
Module Module Module
variable, giving you unpredictable
results.

Figure no 4.2 Parts of a Visual Basic project


4.3 Project Scope:
An object’s scope indicates how much visibility it has throughout the project
in the procedure where it’s declared, throughout a form or module, or global scope.
There are two types of scope in Visual Basic projects: variable scope and procedure
scope.

Design of Steel Building Structural Element AsPer IS800-2007:


Developing a Computational Tool 28
CHAPTER 4

4.3.1 Variable Scope:


Most often, you use the Dim statement to declare a variable. If you do not
specify the variable type when you use Dim, it creates a variant, which can operate as
any variable type. You can specify the variable type using the As keyword.

Table no 4.1 Visual basic declaring statements.


Keyword Does this
Dim Using Dim alone creates variants. Use the As keyword to specify
variable type.
Private Makes variable available only in the current form/module.
Public Makes variable global-variable is available to the rest of program.
ReDim Reallocates storage space for dynamic array variables.
Static Variable preserves its value between procedure calls.
Type Declares a user type.

Table no 4.2 Variable Type


Bytes of Range
Variable Type
Storage
Boolean 2 True or False
Byte 1 0 to 255
-922,337,203,685,477.5808 to
Currency 8
922,337,203,685,477.5808
1 January 100 to 31 December 9999 and time from
Date 8
0:00:00 to 23:59:59
-79,228,162,514,264,337,593,543,950,335 to
Decimal 12
79,228,162,514,264,337,593,543,950,335
-1.79769313486232E308 to 4.94065645841247E-324
Double 8 for negative values and from 4.94065645841247E-324
to 1.79769313486232E308 for positive values
Integer 2 -32768 to 32767
Long 4 -2147483648 to 2147483648
Object 4 N/A
-3.402823E38 to -1.401298E-45 for negative values
Single 4 and from 1.01298E-45 to 3.402823E38 for positive
values
A variable-length string can contain up to
String N/A approximately 2 billion characters; a fixed-length string
can contain 1 to approximately 64K characters.
User defined
N/A N/A
data type
Variant N/A N/A

4.3.2 Procedure Scope:

Design of Steel Building Structural Element AsPer IS800-2007:


Developing a Computational Tool 29
CHAPTER 4

As with variables, one can restrict the scope of procedures, and one do that
with the Private, Public, Friend and Static keywords. The Private and Public
keywords are the main keywords here; using them, you can specify if a subroutine or
function is private to the module or form in which it is declared or public (that is,
global) to all forms and modules. You use these keywords before the sub or function
keyword.

4.4 The Integrated Development Environment:


The integrated development environment is composed of the following
4.4.1 The menu bar
4.4.2 The toolbar
4.4.3 The project explorer
4.4.4 The properties window
4.4.5 The form layout window
4.4.6 The toolbox
4.4.7 Form designers
4.4.8 Code windows

4.4.1
4.4.2

4.4.3
4.4.7

4.4.4

4.4.6

4.4.8
4.4.5

Figure no 4.3 The Visual Basic Integrated Development Environment

4.4.1 The Menu bar:

Design of Steel Building Structural Element AsPer IS800-2007:


Developing a Computational Tool 30
CHAPTER 4

The menu bar presents the Visual Basic menus. Here is a list of those menus
and what they do.
4.4.1.1 File - File handling and printing; also used to make EXE files.
4.4.1.2 Edit – Standard editing functions, undo, searches.
4.4.1.3 View – Displays or hides windows and toolbars
4.4.1.4 Project – Sets project properties, adds/removes forms and modules, and
adds/removes references and components.
4.4.1.5 Format – Aligns or sixes controls.
4.4.1.6 Debug – Starts/stops debugging and stepping through programs.
4.4.1.7 Run – Starts a program, or compiles and starts it.
4.4.1.8 Tools – Adds procedures, starts the Menu Editor, sets IDE options.
4.4.1.9 Add-ins – Add-in manager, lists add-in like Application Wizard and API
viewer
4.4.1.10 Window – Arranges or selects open windows.
4.4.1.11 Help – Handles Help and the About box

4.4.2 The Toolbar:


The main Visual Basic toolbar appears in figure 4.4. This toolbar contains
buttons matching popular menu items as you can see in figure no 4.4; clicking the
button is the same as selecting a menu item and can save you some time.

Properties Data
Open project Paste Start window
Add form Object view
Cut Undo
module and so on End browser

Add Visual component


project Save Find Break Form Manager
project layout
Toolbox
Project
Copy Redo
Menu explorer
editor

Figure no 4.4 The Visual Basic toolbar

Design of Steel Building Structural Element AsPer IS800-2007:


Developing a Computational Tool 31
CHAPTER 4

4.4.3 The Project Explorer:


The Project Explorer appears in Figure no 4.4. This is the
window that allows one to coordinate the parts of program into folder
for easy manipulation, because all parts of that project appear in the
Project Explorer arranged in a tree view.

Figure no 4.5 The Visual Project Explorer


4.4.4 The Properties Window:
The properties window appears in figure no 4.6. This is where one set an
object’s properties; for example one can set the caption of
command buttons, the text in textboxes, and literally hundreds
of other properties here.

Figure no 4.6 The Properties Window

4.4.5 The Form Layout Window:


The form layout window appears in figure no 4.7. Using this window, one can
position forms as one want them to appear on the screen when they
are first displayed.

Figure no 4.7 The Layout Window


4.4.6 The Toolbox:
The Visual Basic toolbox appears in figure no 4.8. This window is a
mainstay of Visual Basic and indicates what was so revolutionary about
Visual Basic in the first place. The toolbox is used to add controls to the
project and one can do that very easily, just by clicking on the tool such as
command button tool and draw the new button in a form.

4.4.7 Form Designers:


Figure no 4.8 The Toolbox

Design of Steel Building Structural Element AsPer IS800-2007:


Developing a Computational Tool 32
CHAPTER 4

Form designers are really just windows in which a particular form appears. One
can place controls into a form simply by drawing them after clicking the
corresponding control’s tool in the toolbox. Figure no 4.9 shows the form designers.

4.4.8 Code Windows:


Code windows are the windows where the coding is done for a particular object
on the form. As discussed earlier each form have a separate coding window. There
are two drop down list boxes at the top of the code window: the left list is for
selecting the object to add code to and the right list for selecting the procedure to add.

Figure no 4.9 The Form Designers And Code Windows

Design of Steel Building Structural Element AsPer IS800-2007:


Developing a Computational Tool 33

You might also like