Self - Learning Module - 3 - Q4
Self - Learning Module - 3 - Q4
03
Specific Objectives
1. Explain variable and identify the rules in naming a variable.
2. Identify the different data types.
3. Understand and use properly the different types of operators.
Materials
Microsoft Word
Computer
Lesson
Working with Language Elements
1
object name
assignment operator
Label1.Caption = Time
property name
function
Variables can have the same value or change values several times
as needed. There are rules to follow in naming variables.
Start each variable name with a letter. It must be lesser than 256
characters long and does not contain a period.
Use descriptive names.
Example: SalesTaxRate instead of Tax
Use a combination of uppercase and lowercase characters.
Capitalize the first letter of each word, if needed.
Never use Visual Basic keywords, objects or properties as variable
name such as Caption, Label…
Start each variable name with a two or three character
abbreviation. Ex. sName (string data)
The name must be unique within the variable’s scope.
2
6. Run the program. Use the Start button or press F5.
7. Click the Show Button.
8. Click the Exit Button.
Variant variables can store all of data types and change formats
automatically. However, variant variables take too much memory space
unlike the integer values. They are easy to declare and use. They assist in
writing codes faster and more concise.
3
Date 8 bytes Jan.1, 1000 through Dec. Dim Birthday As
31, 9999 Date
Birthday = #3-1-63#
Variant 16 bytes All data type ranges Dim Total
Constants
Const Pi = 3.14159265
4
It provides the following mathematical operators which link the
parts of a formula.
Arithmetic Operators
Operators Description Example Result
+ Add 5+5 10
- Subtract 10 – 5 5
/ Divide 25 / 5 5
\ Integer Division 20 \ 3 6
* Multiply 5*4 20
^ Exponent (power 3^3 27
of)
Mod Remainder of 20 Mod 6 2
division
& String “George”&” “George Bush”
concatenation “&”Bush”
Formula: Answer = 10 + 15 * 2 / 4 ^ 2
Try This!!!
Form =
5
Solve:
No. 1 No. 2 Operation Result
11 2 Integer Division
13 4 Remainder
9 3 Exponentiation
8 5 Concatenation
Number = ( 17 – 5 * 2 ) * 4 ^ 2
Number = ( ( 17 – 5 ) * 2 ) * 4 ^ 2
The result is different. The value in the inner parentheses is 12. The
multiplication in the inner parentheses is 24. The exponentiation is 16. The
multiplication of the two numbers is 384. Parentheses can change the
result of a mathematical operation.
6
same level are evaluated from left to right as they are shown in an
expression.
COMPARISON MEANING
OPERATOR
= Equal to
<> Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
Example:
CONDITIONAL EXPRESSION RESULT
20 < > 40 True (20 is not equal to 40)
Total < 40 True if Total is less than 40; otherwise
False
Total = Label1.Caption True if the Caption property of the Total 1
object contains the same value as the
Total variable, otherwise False
7
Text1.Text = “Jose” True if the word Jose is in the first
textbox; otherwise, False
Example:
Fruit = “Papaya” and Cost < 30 True (both conditions are True)
Fruit = “Bananas” or Cost < 40 True (one condition is True)
Not Cost < 20 True (condition is False)
Fruit = “Papaya” Xor Cost < 30 False (both conditions are True)
EXERCISES
BASIC
A. Identify the following operators.
_____________ 1. + _____________ 5. ^
_____________ 2. - _____________ 6. /
_____________ 3. * _____________ 7. Mod
_____________ 4. \ _____________ 8. &
8
B. Write the order of precedence in the formula. Write 1 to 5.
Answer = ( ( 15 + 16 ) * 8 – 1 ) / 5 * 4
C. Answer briefly.
1. Define the following words:
a. formula c. operators
b. expression d. variable
2. What can parentheses do to the order of precedence of an
expression?
3. What is a part of a program statement that asks True or False
question about property, a variable or another data?
4. Enumerate the different operators used by:
a. comparison operator
b. logical operator
Closure
A. Please check the box if you can do it already.
B. If you have questions in mind, please use the space below to address it.
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
References
Amoto Jr., Tito B. Visual Basic 6.0. Quezon City, Book Craft Publishing Co., Inc.,
2001.
https://www.freetutes.com/learn-vb6/lesson2.html
https://www.tutlane.com/tutorial/visual-basic/vb-data-types