Professional Documents
Culture Documents
Second Lecture Programming in Visual Basic: Page11 - 32
Second Lecture Programming in Visual Basic: Page11 - 32
GUI) applications. The applications have a familiar appearance to the user. Visual Basic
implements graphical user interface that allows the use of graphics for different
applications. It provides visual interactive windows with user, like Dialogue box for
(color, font ...), Input box, and Output box. Also it is able to create menu to simplify user
application. So that when you start a program you have to select which kind of events and
what will be the respond for them.
P a g e 11 | 32
Event: It is what the user makes as actions on the program, like pressing a button or
selecting item from a list, or moving mouse, or clicking mouse button. When events
occurred, windows take this event to the executed program and giving it a message about
the nature of this event that took place on this program, so that the program will analyze
this message and take the right action for this event after the program complete, the
control came back to the operating system. It is not necessary that the program has to
respond to any event, for example moving the mouse on the screen of the program is
considered as an event, but that does not mean the program has to respond to that event,
unless the program is drawing program. Event driving Programming leads to divide the
program into many parts and each one of them will respond to a certain event, and we start
making the code for each part of the program. Visual Basic make this task easy to us, as it
is automatically dividing the program into parts and each part called action (sub routine)
and this action is controlling in a certain action for a certain tool.
P a g e 12 | 32
4- It is able to connect to Internet, and to call Explorer.
P a g e 13 | 32
There are two other tab. Existing tab lets you open existing Visual Basic projects to
edit or modify, while the recent tab provides you with a list of most recently created or
edited Visual Basic projects. To start a new project, click on the Standard.EXE icon and
then click on the open button. The windows shown in Fig. (2-2) will open. We now
explore the components of this windows one by one. The menu bar is at the very top.
Menu bar contains most of the utilities that are available to you in the Visual Basic
environment. Such as File, Edit, View, etc. Click on each of these items to see the
available utilities.
Under the Menu bar is the Toolbar. Toolbar contains some of the most often used
items from the Menu bar in small icons. Move the mouse pointer on each icon and leave it
for a mount and the function of the icon will appear in a small sidebar.
The Toolbox in the Visual Basic environment contains the controls (also refer to as
object) that are most often used in developing applications. Throughout this course you
will learn how to use all these controls.
P a g e 14 | 32
Fig. (2-2): New Project Environment.
P a g e 15 | 32
Table 2-1: Most frequently used controls in the Visual Basic environment
PictureBox You use a picture box to display text or graphics output.
Label You place a label to the left of a text box to tell the user
what type of information to enter into the text box. You
also use labels to display output.
TextBox Holds text that the user can either enter or change or text
generated by application.
ComboBox Combines the features of list box and text box. The user
can either choose an item from the list or enter a value in
the text box.
ListBox Display a list of items from which the user can choose
one.
P a g e 16 | 32
Shape Used to draw a variety of shapes such as a rectangle,
square, rounded square, oval, or circle, etc.
There are three other windows that appear in the Visual Basic environment. They
are Project window, Properties window and the Layout window. The Project window
provides an explorer type view of all the forms and modules in the project, while
Properties window a list of all the properties available for each control with their
corresponding value.
Layout window shows the relative location of the forms on the screen. As you
change the location and size of the forms the changes are reflected in the Layout window.
Fig. (2-6) shows Visual Basic’s Project Window, Properties window and Form Layout
window. You can change the location of the application window (the form) by moving its
location in the Form Layout window. To change of the Form in the Form Layout window
simply click on it (where it’s written Form1) and drag it to and location in the monitor’s
picture.
P a g e 17 | 32
Fig. (2-6): Visual Basic’s Project Window, Properties window and Form Layout window.
Form window is the main window in the Visual Basic environment. Shown in Fig.
(2-7), this is the window within which the application interface is developed. You develop
the application interface by placing controls in the Form.
Handles
Procedure
Control (Object)
P a g e 18 | 32
Fig. (2-8): Visual Basic’s Code Editing Window.
P a g e 19 | 32
Once the code edit window appears, the control that the code is being written for is
shown in the top left Combo Box and the event procedure is shown in the top right Combo
Box. Visual Basic is an event driven programming language. This simply means that the
applications that are developed using Visual Basic, much like any other windows
applications, will act upon the user’s actions (event procedures) such as Click, Double
Click, Drag Drop, Mouse Down, etc. Whenever you want the control in your application
to respond to an event, you put the instructions in the appropriate event procedure. Of
course the user does not initiate all the events. Sometimes events are consequence of other
events. For example as you start an application the main Form is loaded in the memory
and shows up on the screen. This is a Form-Load event, which simply means that the Load
event procedure is activate on the Form control. Using the arrow in the left Combo Box
will show all the controls that are used in the application and clicking on the arrow of the
right Combo Box shows all the available procedure for the control that is shown on the
left Combo Box.
Control Properties
Every control in a Visual Basic application has certain characteristics called
properties. These properties dictate the way a control looks, size, color, and screen
location amount other things. When you place a control in your application (either by drag
and drop or by double click on it) the property window will display the properties
corresponding to that control. There is a default value for each property. You may change
these values to fit the purposes of your application. Once a control is placed on a Form,
Visual Basic automatically will issue a name for that control. This is the name that the
control will be known by, to the rest of the application. When you write codes for that
control you notice that the name that Visual Basic has given to this control appears in the
top left Combo Box of the code edit window. This name can be changed, just like any
other property that appears in the property window. Fig (2-9) shows a Form that has a
Command Button control placed in it.
P a g e 20 | 32
Once a control like the Command Button control is placed on the Form, it has
“Command1” written on it. This is called the Caption. This may become a little confusing since
the Name property of the control that is also “Command1”. In other word, both the Name and
Caption (what appears in the Command Button control) properties have the same value. To
distinguish between them, the Caption on the Command Button control was changed to “Click on
me” and the Font property was changed too.
Another noteworthy item is that when there are more than one control present in the
application during the design time, the properties of the control that is selected will appear
in the Properties window. Note the handles around the Command Button control in Fig.
(2-9), these handles are indicators that Command Button control has been selected.
P a g e 21 | 32