Computer 10 Module 12 and 13
Computer 10 Module 12 and 13
Fundamentals of Object-
Oriented Application Development
Module 14 (Week 1 & 2)
Programming
Lesson 6 Fundamentals in Visual
Basic 2005
Visual Basic is a
third- generation event-
driven programming
language first released by
Microsoft in 1991. It evolved from the earlier DOS
version called BASIC. BASIC means Beginners' All-purpose Symbolic Instruction Code. Since then
Microsoft has released many versions of Visual Basic, from Visual Basic 1.0 to the final version Visual Basic
6.0. Visual Basic is a user-friendly programming language designed for beginners, and it enables anyone to
develop GUI window applications easily..
What’s In
Direction: Identify the following questions. Write your answer in the answer sheet provided.
Constants
are containers whose values, once set, will cannot be changed.
when defining a constant, it is needed to use the Const keyword and specify the constant's name,
data type, and value in the following manner: Const name As datatype = value
For example:
o Const pi As Single = 3.14159265358979
Variables
are containers whose values can be changed.
When declaring a variable, it is needed to use the Dim keyword and specify the variable’s name
and data type.
Optionally, we can also specify its initial value. Variable declarations look like constant
definitions except that the Dim keyword is used before the variable name.
For example:
o Dim index As Integer = 0
o Dim index1, index2, index3 As Integer
Data Types
The data type of a constant or variable denotes the possible values that the constant or variable can
have. For example, if a variable is Integer data type, then the values that it can contain can range
from 2,157438,648 to 2,147,483,647.
The most commonly used Visual Basic data types, their value ranges, and common uses are
shown in table 1.0.
Commonly Used Visual Basic Data Types and Their Common Uses
Data Type Value Range Common Use
To store a number that contains no
Integer - 2,157,438,648 to 2,147,483,647
decimal places
-3.4028235E+38 through 1.401298E-
Single (Single precision floating 45 for negative values; 1.401298E-45 To store a number that contains
point) through 34028235E+38 for positive decimal places
values
Up to 29 significant digits and can
Decimal represent values in excess of 7.9228 x Currency; Financial calculations
10?
To store only a True
Boolean True or False
or a False value
0 to approximately 2 billion Unicode
String To store text
characters
Table 1.0 Commonly used Visual Basic Data Types and their Common Uses
Arithmetic Operators
- Arithmetic operators are used to perform any of the familiar arithmetic operations that involve the
calculation of numeric values represented by literals, variables, other expressions, function and property calls,
and constants.
Examples:
You can add two values in an expression together with the + Operator, or subtract one from another
with the – Operator
Negation also uses the - Operator, but with only one operand
Exponentiation uses the ^ Operator
Assignment Operators
are used to assign values on a containers.
c <<= 2
<<= LEFT SHIFT AND ASSIGNMENT operator.
(same as c = c << 2)
c >>= 2
>>= RIGHT SHIFT AND ASSIGNMENT operator.
(same as c = c << 2)
c &= 2
&= BITWISE AND ASSIGNMENT operator.
(same as c = c << 2)
c ^= 2
^= BITWISE EXCLUSIVE OR and ASSIGNMENT operator.
(same as c = c << 2)
c |= 2
|= BITWISE INCLUSIVE OR and ASSIGNMENT operator.
(same as c = c << 2)
Comparison Operators
compare two expressions and return a Boolean value (True or False) that represents the
relationship of their values.
Examples:
a=0<1 (The value of a will be TRUE since 0 < 1 is a correct statement.)
b=0>1 (The value of b will be FALSE since 0 > 1 is an incorrect statement.)
c = Not a (The value of c will be FALSE, since it negates the value of a which is TRUE)
Concatenation Operators
- join multiple strings into a single string. The most commonly used concatenation operator is the &
operator.
For example,
Dim x, y, Z As String
x = "Hello"
y="World"
z = x & “,” & y & “!”
The result of the statement above, the ‘z’ will be set to “Hello, World!”.
String Functions
Len() – returns the length of the string.
Example: Len(“Hello”) - would return a value of 5, since the number of characters inside the
string (Hello) is 5.
Chars() – returns the character at a given position in the string, where the first character is at
position 0.
Example: “Hello”.Chars(0) – will return the character ‘H’, while “Hello”.Chars(4) will return
the character ‘o’.
Exercise:
Given:
Dim x,y,z As String
x = “Computer”
y = “Science”
z = “Technology”
Direction: Identify the following questions. Write your answer in the answer sheet provided. [10 points]
Direction: Enumeration.
1 – 5 Common Visual Basic Data Types
6 – 10 Common Visual Basic Arithmetic Operators
11 -13 Common Visual Basic Logical Operators
14 – 15 Common Visual Basic Comparison Operators
Direction: Differentiate the term const, variable, and data types. [5 points]
Direction: Identify the result of the given questions.
Given:
Dim x, y, z As Integer
Dim a, b As String
x = 24
y = 35
z = x + y + 30
a = “Today’s”
b = “World”
c = a & “ “ & b
1. len(c) = 6. y -= 20 =
2. c.Chars(3) = 7. “Hello ” & b =
3. z = 8. a & “ event” =
4. x += 24 = 9. c =
5. c.Chars(y – 34) = 10. z – x =
____________________________________________
_________________________________
ANSWER SHEET
I. What’s More
Direction: Identification. [10 points]
1. 6.
2. 7.
3. 8.
4. 9.
5. 10.
Direction: Differentiate the terms constants, variables, and data types. [5 points]
IV. Assessment