0% found this document useful (0 votes)
46 views42 pages

Csit Visual Basic Material

Visual Basic is a programming language used to build graphical user interface (GUI) applications for Windows. It evolved from the BASIC language. The Visual Basic environment provides a form designer for building application interfaces and a toolbox of common controls. A Visual Basic application consists of forms for the user interface, controls on the forms, properties of the controls, event procedures triggered by user interactions, and general procedures. Variables are used to store and manipulate data in an application and have specific data types like strings, integers, and floating point numbers. Operators perform arithmetic, relational, and logical functions on variable values.

Uploaded by

progiestudio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views42 pages

Csit Visual Basic Material

Visual Basic is a programming language used to build graphical user interface (GUI) applications for Windows. It evolved from the BASIC language. The Visual Basic environment provides a form designer for building application interfaces and a toolbox of common controls. A Visual Basic application consists of forms for the user interface, controls on the forms, properties of the controls, event procedures triggered by user interactions, and general procedures. Variables are used to store and manipulate data in an application and have specific data types like strings, integers, and floating point numbers. Operators perform arithmetic, relational, and logical functions on variable values.

Uploaded by

progiestudio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

INTRODUCTION

 History of a visual basic


 A brief description of visual basic
 Getting to know the visual Basic environment
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.
History of a 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 controls, deleted 16 bit application
support.
 And, now Visual Basic 6.0 - some identified new features of
Visual Basic 6.0:
 Visual basic 2008 was launched by Microsoft word in 2008
A brief description of Visual Basic

VISUAL BASIC is a high-level programming language evolved


from the earlier DOS version called BASIC. BASIC stands for
Beginners' All-purpose Symbolic Instruction Code. The
program codes in Visual Basic resembles the English language.
Different software companies produce different versions of
BASIC, such
as Microsoft QBASIC, QUICKBASIC, GWBASIC, and IBM
BASICA and so on.
Introduction cont’d
Visual Basic is an easy programming language to learn and it is
for anybody who is interested in programming but lack
professional training in software engineering.

Learning VB will help young children to improve their logical


thinking skills and
develop their minds. You can choose to program in VB purely
for fun and enjoyment or you can create more advanced
applications such as educational courseware and commercial
software.
Introduction cont’d
VISUAL BASIC is a VISUAL and events driven Programming
Language. These are the main differences from the old BASIC.
In BASIC, programming is done in a text-based environment and
the program is executed sequentially. In VISUAL BASIC,
programming is done in a graphical environment. In old BASIC,
you have to write a text-based procedure to design the interface,
but Visual Basic enables you to design the interface by dragging
and resizing the objects as well as changing their colors, just like
any windows-based programs.
Introduction cont’d
Visual Basic is event-driven because users may click on a certain
object randomly, so each object has to be programmed
independently to be able to response to those actions (events).
Examples of events are clicking a command button, entering text
into a text box, selecting an item in a list box etc.
1.2 The Visual Basic Environment
Upon start up, Visual Basic 8.0 will display the dialog box, you can
choose to start a
1. Create project
2. Open an existing project or
3. Select a list of recently opened programs.
A project is a collection of files that make up your application.

There are various types of applications that can be created;


however, we shall concentrate on creating Standard EXE
programs (EXE means executable program). Now, click on the
Standard EXE icon to go into the VB programming environment.
Visual basic environment

Figure 1.1 Visual Basic 8.0 Start-up Dialog Box


Visual Basic 8.0 Start-up Dialog Box

2
1

5 3
4

Figure 1.2 Visual Basic 8.0 IDE


Visual Basic environment cont’d
1. A blank form for you to design your application's interface.

2. The project window which displays the files that are created in
your application.

3. The properties window which displays the properties of various


controls and objects that are created in your application.

4. Toolbox that consists of all the controls essential for developing


a VB Application.

5. Error list window which displays the error in your program


Visual Basic environment cont’d
The controls include text boxes, command buttons, labels,
combo boxes, picture boxes, image boxes, timers and other
objects that can be dragged to and drawn on the form to
perform certain tasks according to the events assigned to
them.
The controls for Standard.EXE window is shown in Figure 1.3.
Visual Basic environment cont’d

Figure 1.3: The controls available for a Standard.exe


project
Application (Project) is made up of:
1. Form- Windows that you create for user interface
2. Controls - Graphical features drawn on forms to allow user
interaction (text boxes, labels, scroll bars, command buttons,
etc.) (Forms and Controls are objects.)
3. Properties - Every characteristic of a form or control is specified
by a property. Example properties include names, captions,
size, color, position, and contents. Visual Basic applies default
properties. You can change properties at design time or run
time.
4. Methods - Built-in procedure that can be invoked to impart
some action to a particular object.
Application (Project) is made up of cont’d

5. Event Procedures - Code related to some object. This is


the code that is executed when a certain event occurs.
6. General Procedures - Code not related to objects. This
code must be invoked by the application.
7. Modules - Collection of general procedures, variable
declarations, and constant definitions used by application.
1.3 Steps in Building a Visual Basic
Application
There are three basic steps in building a VB application, as
follows:
Step1. Draw the user interface
Step2. Assign properties to controls
Step3. Attach code to controls
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
VARIABLES IN VISUAL BASIC
Variables: are used by Visual Basic to hold information needed
by your application.
In other word Variables are name spaces in a computer
memory.
Rules for naming variables
 visual basic is case sensitive
 More than 40 characters but less than 255
 They may include letters, numbers, and underscore (_)
 The first character must be a letter
 You cannot use a reserved word (word needed by Visual
Basic)
 You cannot use a space, period (.), or characters @, &, $, # in
the name.
Examples of valid and Invalid variables
names
Valid Invalid
My_Car My.Car
ThisYear 1thisYear
Long_Name_Can_Be_Use He&His friends
Long_Number Long
Velocity 2velocity etc
Data type
Let's discuss about a very simple but very important concept
available in almost all the programming languages which is called
data types.
As its name indicates, a data type represents a type of the data
which you can process using your computer program. It can be
numeric, alphanumeric, decimal, etc.
Examples.
10 + 20
10.50 + 20.50
Data types cont’d
The two examples are straightforward. Now let's take another
example where we want to record student information in a
notebook.
Here we would like to record the following information:
• Name:
• Class:
• Section:
• Age:
• Sex:
Now let assign value to the record above
Data types cont’d
 Student name “David Ayuba" is a sequence of characters
which is also called a string.
 Student class “2nd" has been represented by a mix of whole
number and a string of two characters. Such a mix is called
alphanumeric.
 Student section has been represented by a single character
which is ‘P'.
 Student age has been represented by a whole number which
is 13.
 Student sex has been represented by a single character which
is ‘M'.
DATA TYPES IN VB
Visual Basic Data Types
1. Boolean
2. Integer
3. Long (Integer)
4. Single (Floating)
5. Double (Floating)
6. Currency
7. Date
8. Object
9. String
10. Variant e.t.c
VARIABLES
Variables are the names you give to computer memory locations
which are used to store values in a computer program.
For example, assume you want to store two values 10 and 20 in
your program and at a later stage, you want to use these two
values. Let's see how you will do it. Here are the following three
simple steps:

1. Create variables with appropriate names.


2. Store your values in those two variables.
3. Retrieve and use the stored values from the variables.
Declaring variables
Variables need to be declared before using them by assigning
names and data types. variables declared within a procedure
follow the key word DIM and precede the keyword AS, this
format is illustrated below
Dim Variable Name As type Name
Examples
Dim pi as constant Dim Salary as single
Pi=3.1428 Salary = 12000.15

Dim speed as integer Dim PassWord as String


Speed=65 PassWord = “ “
Visual Basic Operators
Arithmetic Operators
The simplest operators carry out arithmetic operations. These
operators in their order of precedence are:
Operation Operator
1. Exponentiation ^
2. Multiplication and division */
3. Integer division (truncates) \
4. Modulus Mod
5. Addition and subutraction +-
Visual Basic Operators
Parentheses around expressions can change precedence. ()
To concatenate two strings, use the & symbol or the + symbol:
Relational Logical operators
There are six comparison operators in Visual
Basic.
Relational Operators Meaning
1 < Less than
2 > Greater than
3 <= Less than or Equal to
4 >= Greater than or Equal to
5 = Equal to ( Assignment Op)
6 <> Not equal to
Logical operators
S/N Logical operators Meaning
1 AND True if all expressions are true
2 OR True if one of the expressions are true
3 NOT Negates the true
4 OR One must be true but not all
5 EQU True when the expressions are the same i.e both
true or both false
Selected library maths Function
S/N Function Computes1
1 Math.log(x) Log to base e
2 Math.abs(x) Absolute values
3 Math.exp(x) Exponentiation
4 Math.sqrt(x) Square root of x
5 Math.sin(x) Sine of angle x
6 Math.cos(x) Cosine of angle x
7 Math.tan(x) Tangent of angle x
Tool Box / Basic Controls
Visual basic provide a huge variety of controls that help you to
create rich user interface GUI. The following are basic controls
that we are going to look into
1. Forms 10. List box
2. Textbox 11. Scroll bar
3. Button 12. Data time Picker
4. Label
5. Radio button
6. Check box
7. Combo box
8. Picture box
9. Progress bar
OBJECT

An object is a type of user interface element you create on a


visual basic form by using a toolbox. In fact, in visual basic the
form itself is an object. Every visual basic object consist of three
important element.

1. Properties:- which describe the object


2. Method:-Couse an object to do something
3. Event:- Are what happens when an object does something
PROPERTIES
Properties:- Is the characteristic you want to change. All visual
basic object can be Moved, resized, or customized by setting
their properties. To set a property

Syntax OBJECT.PROPERTIES.VALUE
An Object is the name of the object you are customizing
Value is the New properties setting

Messagebox.show(“ Hello World”)


Method/Event
Method is procedure, they Couse an object to do something
method are used to access or manipulate the characteristic of an
object.
For example the message box control has a method name SHOW

An Event is signal that informs an application that something


important has occurred, for example when a user click a control
on a form click to Load.
Form
Properties, Method and Event
Properties Method Event
Back color show click
Border style hide double click
Top left send back load
Top close resize
Decision-Making Statements

Decision making structures require that the programmer specify


one or more conditions to be evaluated or tested by the
program, along with a statement or statements to be executed if
the condition is determined to be true, and optionally, other
statements to be executed if the condition is determined to be
false.
The following is the general form of a typical decision making
structure found in most of the programming languages
General form of decision making
Decision making

Visual basic provides the following types of decision making


statements
• If then statement
• If then else statement
• If then………. elseif…….
If ……then statement
It is the simplest form of control statement, frequently used in
decision making and changing the control flow of the program
execution.
Syntax for If ……then statement
If condition then
[ statement (s)]
End if
Where, condition is a Boolean or relational condition and
statement(s) is a simple or compound statement.
If ……then statement cont’d
a = 15
If(a <= 20) then
C = c+1
End if
If the condition evaluates to true, then the black of code inside
the if statement will be executed. If the condition evaluate to
false, the first set of code after the end of the if statement (after
the closing End If) will be executed

You might also like