Computer Program PDF

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

Computer program

Visual basic programming

By
Hussein Nail Hassan
Stage One
Section B
Morning study
8
Supervisor by
Abdulmuttalib Rashid

2019-2020

1
Index
-Introduction

1. What is Visual Basic


2. Some Features of Visual Basic
3. Why Visual Basic
4. What Visual Basic is not
5. When You Program in Visual Basic
6. Visual Basic 6.0 versus Other Versions of Visual Basic
7. 16 Bits versus 32 Bits

- Structure of a Visual Basic Application

1. Steps in Developing Application


2. Drawing the User Interface and Setting Properties

- Setting Properties of Objects at Design Time

-Setting Properties at Run Time

-How Names are Used in Object Events

-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 .

Some Features of Visual Basic


1- Full set of objects - you 'draw' the application
2- Lots of icons and pictures for your use
3- Response to mouse and keyboard actions
4- Clipboard and printer access
5- Full array of mathematical, string handling, and graphics functions
6- Can handle fixed and dynamic variable and control arrays
7- Sequential and random-access file support
8- Useful debugger and error-handling facilities
9- Powerful database access tools, Package & Deployment Wizard makes
distributing your applications simple, ActiveX support

Why Visual Basic?


Programming for the Windows User Interface is extremely complicated.
Other Graphical User Interfaces (GUI) are no better.
Visual Basic provides a convenient method for building user interfaces.
Visual Basic can interface with code written in C, for efficiency.

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.

When You Program in Visual Basic:


You draw pictures of your user interface.
You draw buttons, text boxes, and other user-interface items.
You add little snippets of code to handle the user interaction.
You add initialization code, usually as the last step.
If you like, you can code more complex functions. (But many do not.)

Visual Basic 6.0 versus Other Versions of Visual Basic


• The original Visual Basic for DOS and Visual Basic for Windows were
introduced in 1991.
• Visual Basic 3.0 (a vast improvement over previous versions) was
released in 1993.
• Visual Basic 4.0 released in late 1995 (added 32-bit application support).
• Visual Basic 5.0 released in late 1996. New environment, supported
creation of ActiveX controls, deleted 16-bit application support.
• And, now Visual Basic 6.0 - some identified new features of Visual
Basic 6.0:
1. Faster compiler
2. New ActiveX data control object
3. Allows database integration with wide variety of applications
4. New data report designer
5. New Package & Deployment Wizard
6. Additional internet capabilities

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

• There are three primary steps involved in building a Visual Basic


application:
1. Draw the user interface
2. Assign properties to controls
3. Attach code to controls
Drawing the User Interface and Setting Properties
• Visual Basic operates in three modes.
1. Design mode - used to build application
2. Run mode - used to run the application
3. Break mode - application halted and debugger is available

• Six windows appear when you start Visual Basic.


The Main Window 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. The toolbar has
buttons that provide shortcuts to some of the menu options. 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.

• The Form Window is central to developing Visual Basic applications. It is


where you draw your application.

7
The Toolbox is the selection menu for controls used in your application.

• The Properties Window is used to establish initial property values for


objects. The drop-down box at the top of the window lists all objects in
the current form. Two views are available: Alphabetic and Categorized.
Under this box are the available properties for the currently selected
object.

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.

• As mentioned, the user interface is ‘drawn’ in the form window. There


are two ways to place controls on a form:
1. Double-click the tool in the toolbox and it is created with a default
size on the form. You can then move it or resize it.
2. Click the tool in the toolbox, 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.

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:

The drop-down box at the top of the


Properties Window is the Object box. It
displays the name of each object in the
application as well as its type. This
display shows the Form object. The
Properties list is directly below this box.
In this list, you can scroll through the list
of properties for the selected object. You
may select a property by clicking on it.
Properties can be changed by typing a
new value or choosing from a list of
predefined settings (available as a drop-
down list). Properties can be viewed in
two ways: Alphabetic and Categorized.

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.

Setting Properties at Run Time


• You can also set or modify properties while your application is running.
To do this, you must write some code. The code format is:
ObjectName.Property = New Value
Such a format is referred to as dot notation. For example, to change the Back
Color property of a form name frmStart, we'd type:
frmStart.BackColor = BLUE

How Names are Used in Object Events


• The names you assign to objects are used by Visual Basic to set up a
framework of event-driven procedures for you to add code to. The format
for each of these subroutines (all object procedures in Visual Basic are
subroutines) is:
Sub ObjectName_Event (Optional Arguments)
.
.
End Sub
• Visual Basic provides the Sub line with its arguments (if any) and the
End Sub statement. You provide any needed code.

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.

• Variables are used by Visual Basic to hold information needed by your


application. Rules used in naming variables:
1. No more than 40 characters
2. They may include letters, numbers, and underscore (_)
3. The first character must be a letter
4. You cannot use a reserved word (word needed by Visual Basic)

Data Type Suffix


Boolean None
Integer %
Long (Integer) &
Single (Floating) !
Double (Floating) #
Currency @
Date None
Object None
String $
Variant None

• There are three ways for a variable to be typed (declared):


1. Default
2. Implicit
3. Explicit

• 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

• To implicitly type a variable, use the corresponding suffix shown above


in the data type table. For example,

12
Text Value$ = "This is a string"

creates a string variable, while

Amount% = 300

creates an integer variable.

• There are many advantages to explicitly typing variables. Primarily, we


insure all computations are properly done, mistyped variable names are
easily spotted, and Visual Basic will take care of insuring consistency in
upper and lower case letters used in variable names.
• To explicitly type a variable, you must first determine its scope. There are
four levels of scope:

1. Procedure level
2. Procedure level, static
3. Form and module level
4. Global level

• Within a procedure, variables are declared using the Dim statement:


Dim MyInt as Integer
Dim MyDouble as Double
Dim MyString, YourString as String
Procedure level variables declared in this manner do not retain their
value once a procedure terminates.
• To make a procedure level variable retain its value upon exiting the
procedure, replace the Dim keyword with Static:

Static MyInt as Integer


Static MyDouble as Double

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:

Dim MyInt as Integer Dim


MyDate as Date

• 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:

Global MyInt as Integer


Global MyDate as Date

• 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.

- Newman, Sally, and Jacob B. Lowenstern. "VolatileCalc: a silicate melt–


H2O–CO2 solution model written in Visual Basic for excel." Computers
& Geosciences 28.5 (2002): 597-604.

- Wolfe, Jeremy M., and Jennifer S. DiMase. "Do intersections serve as


basic features in visual search?." Perception 32.6 (2003): 645-656.

- Schneider, David I. An introduction to programming using visual basic


2012. Prentice Hall Press, 2013.

- Sundberg, Mark L. VB-MAPP Verbal Behavior Milestones Assessment


and Placement Program: a language and social skills assessment
program for children with autism or other developmental disabilities:
guide. Mark Sundberg, 2008.

- Tylee, Lou. "Learn Visual Basic 6.0." Database 8 (1998): 24.

- Lassesen, Ken. "Creating 16-Bit and 32-Bit Screen Savers with Visual
Basic." (1995).

- Petroutsos, Evangelos. Mastering Database Programming with Visual


Basic 6. SYBEX Inc., 1999.

- Corrington, Robert E., et al. "Defining the visual appearance of user-


interface controls." U.S. Patent No. 7,398,472. 8 Jul. 2008.

- Li Y, Gounares AG, Garrett CD, Krajec RS, inventors; Concurix Corp,


assignee. Runtime Memory Settings Derived from Trace Data. United
States patent application US 13/853,791. 2013 Aug 29.

- Grundgeiger, Dave. Programming Visual Basic. NET. O'Reilly, 2018..

- Holzner, Steven. Visual Basic 6 Black Book. Coriolis, 1998.


- Vick P. The Visual Basic. Net Programming Language. Addison-Wesley
Professional; 2004.

15

You might also like