Visual Basic Module
Visual Basic Module
Advantages of Flowchart
I. DATA TYPES – A program handles different data to be III. CONSTANT – are values that do not change during
processed by the computer. These data are classified the execution of the program.
into different types. Ex.
Pi = 3.1416
1. Numeric Data – These are numbers, whole or real X = 100
a. Integer – whole number; 0 – 9
Ex. 20, 105, 289067 IV. OPERATORS – are symbols that indicates the
operation to be performed on the data.
b. Float or Double – Number with decimal
Ex. 5.19, .069, 99.99, 150.9678 Classification of Operators
1. Arithmetic Operators – operators that represent
2. Aphanumeric Data – These are numbers, alphabets or mathematical operations.
special characters.
a. Number – numbers that cannot be used for FUNCTION OPERATOR EXAMPLE RESULT
mathematical operations. Addition + 8+1 9
Ex. 1, 36, 500 Subtraction - 8-1 7
Multiplication * 8*8 64
b. Character – a single letter or special character Division / 8/4 2
Ex. A, L, c, #, $, @3. Exponentiation ^ 8^2 64
Modulus* Mod 8 mod 5 3
c. String – A combinations of characters Negation** - -8 -8
Ex. 5th, Add_Num, 3A, #5 Anahaw St.,
Anna_Reyes *Modulus returns the remainder of a division
Examples: 7 mod 2 result: 1
3. Date and Time – These hold the day, month and the 6 mod 2 result: 0
year for the date and hour, minute and second for the **Negation stands for the negative value
time. Examples: -8
Ex. 4/14/1983, 12:45:30 -50
4. Logical Data – logical data type has only two (2) values; 2. Relational Operators – operators that are used to
True or False. False is equivalent to zero while True holds compare two values based on certain condition.
any other values. FUNCTION OPERATO EXAMPLE RESULT
Ex. True, False R
Greater than > 8>5 True
II. VARIABLE – Different types of data are stored in
Less than < 8<5 False
variables. A variable is a named area in the memory,
Equal to = 8=8 True
which holds temporary data. A program can handle
Not equal <> 8<>5 True
A. If Statements
This is used to evaluate a condition or check a value as
“true” or “false”. If the condition is not met, the
succeeding statements will be executed. Numbe
r =5?
Syntax: If Condition
Statement
End If
Example:
C. Case Statement
1. Input a grade. If the grade is greater than or equal to The Case statement is similar to the use of If…Then…Else
75, display the message “You passed the subject”, statement. It is used when a variable is compared to
otherwise display “Needs of Improvement”. different values or expressions.
Algorithm: Syntax:
Integer Grade
Begin Select Case test expression
Input Grade Case Expresionlist1
If Grade >= 75 Statement Block1
Display “You passed the subject” Case Expresionlist2
Else Statement Block1
Display “Needs of Improvement”
End If End Select
Example:
Flowchart:
Conduct Grade Equivalent
1 – Excellent
Begin 2 – Very Good
3 – Good
4 – Satisfactory
5 – Needs Improvement
MsgBox
Source: Visual “WELCOME”
Basic (An Introduction to OOP)
By: Emily F. Trajano Page 7
END
Print “Satisfactory”
Case “5”
Print “Needs Improvement”
End Select
End Sub
Flowchart:
Begin
Character
Conduct
Input Conduct
Number MsgBox
=5? “WELCOME
”
END
Syntax:
For counter is = start to end (Step Increment)
Statements
Next Counter Counte
r=5
Example:
Algorithm:
Integer Counter
B. Do… While Loop
Begin
Counter = 1
This is used to evaluate a condition if “true” or “false”. If
For Counter = 1 to 5
the condition is true, the statements given are executed.
Print “Count the number of loops.”
If false, the loop will stop and the action is terminated.
Counter = Counter + 1
Integer Age
Begin
Do While Age >= 18
Input Age
Print “You can vote”
Loop
End
Flowchart:
Begin
Integer
Age
Input Age
END
Source: Visual Basic (An Introduction to OOP)
By: Emily F. Trajano Page 10
Examples: clicking of a button, clicking of a menu, loading
of form.
Do-While-Statement
Example:
1. Design and develop a simple looping statement
program that generates the given sequence numbers
V/B Module No. 5 using the Do-While-Loop syntax. Follow the given figure
USING CONTROLS WITH LOOPING STATEMENTS in the designing and developing the application system.
Command
Button
Procedure:
1. Start a new project and select the Standard EXE on the
given displayed items, then click the open command
button. Set the caption of the Form to For-Next-Loop.
2. Click a command button in the Toolbox to add it into
the form. Position it properly and adjust its width
appropriately.
Syntax:
[Link]
Example No. 1
Design and develop a simple program that demonstrates
how to preload a collection of items into the list box. The
user should be able to remove a selected item on the list,
one at a time. Follow the given figure below in designing
V/B Module No. 6 and developing the application program.
COMMON PROPERTIES FOR LIST BOX AND COMBO BOX
CONTROL
Where:
Object either list box or combo box
Index the position of the item in the list
String express specifying the list item
List Box
Command
Button List Box 1
Code:
Private Sub Form_Load()
[Link] "Kare-kare"
[Link] "Inihaw na Liempo"
Code: [Link] "Adobong Manok"
Private Sub Command1_Click() [Link] "Bicol Express"
[Link] [Link] [Link] "Nilagang Baka"
End Sub [Link] "Paksiw na Bangus"
[Link] "Menudo"
Private Sub Form_Load() [Link] "Sinigang na Hipon"
[Link] "Kare-kare" End Sub
[Link] "Inihaw na Liempo"
[Link] "Adobong Manok" Private Sub List1_Click()
[Link] "Bicol Express" 'Additem to List Box 2
[Link] "Nilagang Baka" [Link] [Link]
[Link] "Paksiw na Bangus" End Sub
[Link] "Menudo"
[Link] "Sinigang na Hipon" Example No.4
Text Box 1
List Box 2
Code:
Private Sub Form_Load()
Code: [Link] = ""
Private Sub Form_Load() [Link] "Germany"
[Link] "Java" [Link] "Philippine"
[Link] "C++" [Link] "Singapore"
[Link] "Perl" [Link] "Japan"
[Link] "Visual Basic" [Link] "Alaska"
[Link] "Visual FoxPro" [Link] "California"
[Link] "Turbo Pascal" [Link] "Italy"
[Link] "COBOL" End Sub
[Link] "HTML" Private Sub List1_Click()
End Sub If [Link] = "Germany" Then
Private Sub List1_Click() [Link] = ""
'Additem to the other List Box [Link] = "Germany is in Europe"
[Link] [Link] ElseIf [Link] = "Philippine" Then
‘Remove the Item from the List Box [Link] = ""
[Link] [Link] [Link] = "Philippines is in Asia"
End Sub ElseIf [Link] = "Singapore" Then
Private Sub List2_Click() [Link] = ""
'Additem to the other List Box [Link] = "Singapore is in Asia"
[Link] [Link] ElseIf [Link] = "Japan" Then
B. CONSTANT
A constant stores value that does not change during the
execution of the procedure.
2 Types of Constant
B. IMAGE
Image control displays picture on a form.
Image
A. FRAME
Frame is used to group several controls. When you move
a frame, all the controls inside will be move together
with the frame. You have to create the frame first and
create the controls inside after it.
C. OPTION BUTTON
The common controls placed inside a frame are the Option buttons are also called radio buttons. It is used to
option buttons and the check boxes. allow users to select only one button at a time in a group
of options.
Frame:
Frame
Option
Button
Code:
Option Explicit
Private Sub Option1_Click()
Dim opt1 As String
If [Link] = True Then
[Link] = "FRESHMAN"
Private Sub Check1_Click()
End If
If [Link] = 1 Then
End Sub
opt1 = "Java"
Else
Private Sub Option2_Click()
opt1 = ""
If [Link] = True Then
End If
[Link] = "SOPHOMORE"
End Sub
End If
End Sub
Private Sub Check2_Click()
If [Link] = 1 Then
Private Sub Option3_Click()
opt2 = "Visual Basic"
If [Link] = True Then
Else
[Link] = "JUNIOR"
opt2 = ""
End If
End If
End Sub
End Sub
Private Sub Option4_Click()
Private Sub Check3_Click()
If [Link] = True Then
If [Link] = 1 Then
[Link] = "SENIOR"
opt3 = "Data Structure"
End If
Else
End Sub
opt3= ""
End If
End Sub
C. CHECK BOX
Private Sub Check4_Click()
Check boxes allow users to select several boxes at a time
If [Link] = 1 Then
in a group of options. Check boxes are grouped and
opt4 = "HTML"
usually placed inside a frame.
Else
opt4 = ""
Menu Editor
Name Description
Caption Name of the menu that will appear
on the form
Name The name called by Visual Basic
when the program runs
V/B Module No. 7
Prefix:
MENUS & TOOL BARS
Good descriptive mnu
names: mnuFile, mnuEdit, mnuHelp
MENU
Shortcut Sets the shortcut key for the menu