Computer Program PDF
Computer Program PDF
Computer Program PDF
By
Hussein Nail Hassan
Stage One
Section B
Morning study
8
Supervisor by
Abdulmuttalib Rashid
2019-2020
1
Index
-Introduction
-Variables
-Reference
2
Introduction
What is Visual Basic
· Visual Basic is a tool that allows you to develop Windows (Graphic User
Interface - GUI) applications. The applications have a familiar appearance to the
user. ·
Visual Basic is event-driven, meaning code remains idle until called upon to
respond to some event (button pressing, menu selection, ...). Visual Basic is
governed by an event processor. Nothing happens until an event is detected.
Once an event is detected, the code corresponding to that event (event
procedure) is executed. Program control is then returned to the event processor .
3
What Visual Basic is not?
Visual Basic is not, a powerful programming language that enables you to do
anything you want.
Visual Basic is not, elegant or fast.
Visual Basic is not, a replacement for C.
Visual Basic is not, anything like any other programming language you have
ever used.
4
16 Bits versus 32 Bits
• Applications built using the Visual Basic 3.0 and the 16 bit version of
Visual Basic 4.0 will run under Windows 3.1, Windows for
Workgroups, Windows NT, or Windows 95
• Applications built using the 32 bit version of Visual Basic 4.0, Visual
Basic 5.0 and Visual Basic 6.0 will only run with Windows 95 or
Windows NT (Version 3.5.1 or higher).
• In this class, we will use Visual Basic 6.0 under Windows 95,
recognizing such applications will not operate in 16 bit environments.
5
Structure of a Visual Basic Application
6
Steps in Developing Application
7
The Toolbox is the selection menu for controls used in your application.
8
• The Project Window displays a list of all forms and modules making up
your application. You can also obtain a view of the Form or Code
windows (window containing the actual Basic coding) from the Project
window.
9
Setting Properties of Objects at Design Time
• Each form and control have properties assigned to it by default when you
start up a new project. There are two ways to display the properties of an
object. The first way is to click on the object (form or control) in the form
window. Then, click on the Properties Window or the Properties Window
button in the tool bar. The second way is to first click on the Properties
Window. Then, select the object from the Object box in the Properties
Window. Shown is the Properties Window for the stopwatch application:
A very important property for each object is its name. The name is used by
Visual Basic to refer to a particular object in code.
A convention has been established for naming Visual Basic objects. This
convention is to use a three-letter prefix (depending on the object) followed
by a name you assign. A few of the prefixes are: -
10
Object Prefix Example
Form frm frmWatch
Command Button cmd, btn cmdExit,btnStart
Label lbl lblStart, lblEnd
Text Box txt txtTime,txtName
Menu mnu mnuExit,mnuSave
Check box chk chkChoice
• Object names can be up to 40 characters long, must start with a letter, must
contain only letters, numbers, and the underscore (_) character. Names are
used in setting properties at run time and also in establishing procedure
names for object events.
11
Variables
• We’re now ready to attach code to our application. As objects are added
to the form, Visual Basic automatically builds a framework of all event
procedures. We simply add code to the event procedures we want our
application to respond to. But before we do this, we need to discuss
variables.
• If variables are not implicitly or explicitly typed, they are assigned the
variant type by default. The variant data type is a special type used by
Visual Basic that can contain numeric, string, or date data
12
Text Value$ = "This is a string"
Amount% = 300
1. Procedure level
2. Procedure level, static
3. Form and module level
4. Global level
13
• Form (module) level variables retain their value and are available to all
procedures within that form (module). Form (module) level variables are
declared in the declarations part of the general object in the form's
(module's) code window. The Dim keyword is used:
• Global level variables retain their value and are available to all
procedures within an application. Module level variables are declared in
the declarations part of the general object of a module's code window. (It
is advisable to keep all global variables in one module.) Use the Global
keyword:
• What happens if you declare a variable with the same name in two or
more places? More local variables shadow (are accessed in preference to)
less local variables. For example, if a variable MyInt is defined as Global
in a module and declared local in a routine MyRoutine, while in
MyRoutine, the local value of MyInt is accessed. Outside MyRoutine, the
global value of MyInt is accessed.
14
Reference
- McManus, J. P. (1999). Database Access with Visual Basic 6. Sams.
- Lassesen, Ken. "Creating 16-Bit and 32-Bit Screen Savers with Visual
Basic." (1995).
15