Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Lecture 3... Visual Basic 6.

Structure of a Visual Basic Application


To run Visual Basic program select, Start> Programs > Microsoft Visual Studio 6.0>
Microsoft Visual Basic 6.0 as shown in Fig.(2-1). When Visual Basic is loaded, the New
Project dialog shown in Fig. (2-2) is displayed.

Fig.(2-1) Computer screen Fig.(2-2) New Project dialog.

The New Project dialog allows the programmer to choose what type of Visual Basic
program to create. Standard EXE, which is highlighted by default, allows the programmer to
create a standard executable. Each type listed in Fig.(2-2) describes a group of related files
called a Project.

1.1 Project (VBP)


Project is a program designed to user application that may be simple (like
calculator program) or complex (like word program). The project types listed in Fig.(2-3)
are the " Visual " in Visual Basic, because they contain predefined features for designing
Windows programs. The project is a collection of files that makes the user program. They
may consist of form, modules, active x controls.
The new project dialog contains three tabs :

 New: creating new project.


 Existing: opening an existing project.
 Recent: opening a project that has been previously loaded into the IDE.

1
Lecture 3... Visual Basic 6.0

1.2 Elements of Integrated Development Environmental (IDE).


Figure (2-3) shows The IDE after Standard EXE is selected. The top of the IDE
window (the title bar) displays ―Project1-Microsoft Visual Basic [design].The
environment consists of various windows when Visual Basic is started (by default):

Main
window
Project
Window
Form
window
Properties
Window

Toolbox `
Controls

Form
Layout
Code Window
window

Fig. (2-3) visual basic windows

1- Main Window: as shown in Fig. (2-4) consists of the title bar, menu bar, and
toolbar:
 The title bar indicates the project name, the current Visual Basic operating
mode, and the current form.
 The menu bar has drop-down menus from which you control the operation
of the Visual Basic environment, which Contains a standard command and
specific command like (File, Edit, View, Project, Format, Debug, Run, etc.)
 The toolbar has buttons that provide shortcuts to some of the menu options
and Contains several icons that provide quick access to commonly used
features.

2
Lecture 3... Visual Basic 6.0

The main window also shows the location of the current form relative to the
upper left corner of the screen (measured in twips) and the width and length of the
current form.

Fig. (2-4) Main Window

2- Form1 (Form) window: contains a form named Form1, which is where the
program‘s Graphical User Interface (GUI) will be displayed as shown in Fig. (2-
5).

Fig. (2-5) Form window

3- Toolbox Controls: Contains a collection of tools that are needed for project
design as shown in Fig.(2-6). To show the toolbox press View> toolbox icon. The
user can place the tool on form, and then work with the tool. To place the tool on
form: click on tool>draw tool to form > the tool appears on form or double click
on tool then the tool appears on form. Table (2-1) summarizes the toolbox
controls.
3
Lecture 3... Visual Basic 6.0

Fig. (2-6) Toolbox Window.

Table (2-1): Toolbox controls summary.


Control Description
Used to interact with controls on the form(resize them, move
Pointer
them, etc.). The pointer is not a control
PictureBox A control that display images or print the result.
Label A control that displays uneditable text to the user.
TextBox A control for accepting user input. Textbox can also display text.
Frame A control for grouping other controls
A control that represents a button. The user presses or clicks to
CommandButton
initiate an action.
A control that provides the user with a toggle choice (checked or
CheckBox
unchecked)
Option buttons are used in groups where only one at a time can
OptionButton
be true
ListBox A control that provides a list of items.
ComboBox A control that provides a short list of items.
HscrollBar A horizontal scrollbar.
VscrollBar A vertical scrollbar.
Shape A control for drawing circles, rectangles, squares or ellipse
Line A control for drawing line.
A control accessing the system disk drivers. A control accessing
DrivelistBox
directories on a system
DirlistBox A control accessing directories on a system
Filelistbox A control accessing file in a directory .
A control for displaying images. The images control does not
Image
provide as many capabilities as a picturebox.
4
Lecture 3... Visual Basic 6.0

OLE A control for interacting with other window applications.


A control that performs a task at programmer specified intervals.
Timer
A timer is not visible to the user.

4- Properties Window: The properties window displays the properties for a form or
control as shown in Fig.(2-7). Properties are attributes such as size, position, etc.
like a form; each control type has its own set of properties. Some properties, like
width and height, such as, are common to both forms and controls, while other
properties are unique to form or control. Controls often differ in the number and
type of properties. Properties are listed either alphabetically (by selecting the
alphabetic tab) or categorically (by selecting the categorized tab). The most
important properties of the objects in general are listed in the following table. To
show the properties window press View> properties window icon. Table (2-2)
explain objective of the properties window.

Fig.(2-7) Properties Window


Table (2-2) explanation of the properties window.

Properties
Objective
name
Name Used to represent name of object in code.
Caption Name appears on object.
Back color Background color for object.
Fore color Color of text written on object.
Font Font style type and size
Visible The tool is visible or invisible.
Enable The tool enable or disable
5
Lecture 3... Visual Basic 6.0

Height Length of object


Width Width of object
Top Coordinates of top of object on screen
Left Coordinates of left of object on screen
Text Allows inputting and editing text in object.

5- Form Layout Window: The Form Layout window specifies a form‘s position on
the screen at runtime as shown in Fig.(2-8). The Form Layout window consists of
an image representing the screen and the form‘s relative position on the screen.
With the mouse pointer positioned over the form image, drag the form to a new
location.

Fig.(2-8) Form Layout Window

6- Project Window: displays a list of all forms and modules making up your
application see Fig.(2-9). You can also obtain a view of the Form or Code
windows (window containing the actual Basic coding) from the Project window.

Fig.(2-9) Project Window

Note:

 There are two ways to place controls on a form:


6
Lecture 3... Visual Basic 6.0

1. Double-click the tool in the toolbox and it is created with a default


size on theform. You can then move it or resize it.
2. Click the tool in the toolbox, and then move the mouse pointer to the
form window. The cursor changes to a crosshair. Place the crosshair at
the upper left corner of where you want the control to be, press the left
mouse button and hold it down while dragging the cursor toward the
lower right corner. When you release the mouse button, the control is
drawn.
 To move a control you have drawn, click the object in the form
window and drag it to the new location. Release the mouse
button.
 To resize a control, click the object so that it is select and
sizing handles appear. Use these handles to resize the object, as
shown in Fig.(2-10).

Fig.(2-10).
7- Code Editor Window:
Code Editor Window is used to write a VB code for an application. For
each form there is a separate code editor window. It is displayed when
user clicks on form or objectin form. As shown in Fig. (2-11).

Fig.(2-11) Code Editor Window

7
Lecture 3... Visual Basic 6.0

Events:
Events are like electrical switches. The electrical switches are
of many types, so are the events. The form and controls support
events (generation, interaction with mouse and keyboard). The
most important events in Visual Basic are described in the
following table.

Table (2-3) description of the most important events.


It provide the
Event Action taken when
following integers
Click Single click on object.
DbClick Double click on object.
Mouse move Mouse pointer move object. Button ,shift ,X,Y
Key press Pressing a key of the key board. Key Ascii
DragDrop Move object to another place. Source, X, Y
load Loading the object

Practical part

Example 2-1: Design a form such that: in event load, when


project runs, the formbackcolor property changed (chose any
color).

Code:
Private Sub Form_Load()
Form1.BackColor = QBColor(12)
End Sub

Example 2-2: Design a form such that: in event click on form, when
project runs, the title of theform changed to applied science.

8
Lecture 3... Visual Basic 6.0

Exercises:

1-1 Design a standard project has three forms with


backcolors red, blue and green.
2-2 design a standard project that has one form change
the name from form1 to "students"
2-3 Create a standard project with one form the name of the
project "market seals" and the name of the form "stock
markets" and save project on desktop
2-4 Design a form contains label " A.L.I.K.O" in size 14.

You might also like