0% found this document useful (0 votes)
28 views8 pages

Computer 10 Module 12 and 13

This document provides information about Visual Basic fundamentals including arithmetic and logical operations. It contains 3 sections that define constants and variables, arithmetic operators, and assignment operators. The sections explain what constants and variables are, commonly used data types, arithmetic operations symbols like addition and multiplication, and assignment operators like += and -= that perform operations and assignment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views8 pages

Computer 10 Module 12 and 13

This document provides information about Visual Basic fundamentals including arithmetic and logical operations. It contains 3 sections that define constants and variables, arithmetic operators, and assignment operators. The sections explain what constants and variables are, commonly used data types, arithmetic operations symbols like addition and multiplication, and assignment operators like += and -= that perform operations and assignment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

COMPUTER 10

Fundamentals of Object-
Oriented Application Development
Module 14 (Week 1 & 2)

Programming
Lesson 6 Fundamentals in Visual
Basic 2005

Name of Student: Set (A or B):


Grade and Section: School Year: 2020-2021
Teacher: __________________ Date:

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 I Need To Know

At the end of this module, you will be able to:


 Differentiate constants, variables, and data types
 Explain how arithmetic and assignment operators work
 Explain how comparison, and logical operators work
 Explain how concatenation operators and string function works

Direction: Define what an arithmetic operation is.

What’s In

Direction: Identify the following questions. Write your answer in the answer sheet provided.

1. It is also known as instance variable.


2. It is a function or a procedure that the object keeps track of.
3. It is a collective name for attributes and methods of an object.
4. It is the other term for associations.
5. Type of relationship in which all the attributes and methods of a superclass is inherited by subclass.
6. A UML diagram which is used to show the classes used by a particular application.
7. The symbol ‘+’ means that an attribute or method is ___________________.
8. The symbol ‘-‘ means that an attribute or method is ___________________.
9. It is a public method that returns the value of a private attribute.
10. It is a public method that used to specify the value of a private attribute.

Direction: Define what an logical operation means.

A. CONSTANS AND VARIABLES

Constants and variables are containers whose values were used.

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

B. ARITHMETIC AND ASSIGNMENT OPERATORS

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.

Commonly Used Visual Basic Arithmetic Operators


Arithmetic Operation Operator Symbol
Exponentiation ^
Negation -
Multiplication and Division *, /
Integer Division \
Modulus Arithmetic Mod
Addition and Subtraction +, -
Table 2.0 Commonly Used Visual Basic Arithmetic Operators

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.

OPERATOR DESCRIPTION EXAMPLE

Simple assignment operator. ASSIGNS values from right c=a+b


=
side operands to the left side operand (a and b will be assigned to c)

ADD and ASSIGNMENT operator.


c += a
+= It adds the right operand to the left operand and assigns
(same as c = c + a)
the result to the left operand.

SUBTRACT and ASSIGNMENT operator.


c -= a
-= It subtracts the right operand to the left operand and
(same as c = c - a)
assigns the result to the left operand.

MULTIPLE and ASSIGNMENT operator.


c *= a
*= It multiplies the right operand to the left operand and
(same as c = c * a)
assigns the result to the left operand.

DIVIDE and ASSIGNMENT operator.


c /= a
/= It divides the right operand to the left operand and assigns
(same as c = c / a)
the result to the left operand.

MODULUS and ASSIGNMENT operator.


c %= a
%= It takes modulus using two operands and assigns the result to
the left operand. (same as c = c % a)

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)

Table 3.0 Assignment Operators

C. COMPARISON AND LOGICAL OPERATORS

Comparison Operators
 compare two expressions and return a Boolean value (True or False) that represents the
relationship of their values.

Commonly Used Visual Basic Comparison Operation


Comparison Operation Operator Symbol Example
a=5
Equality (equal to) == b=5
a == b (returns true)
a=5
Inequality (not equal to) <> b=6
a <> b (returns true)
a=5
b=6
Less than <
a < b (returns true)
a=5
Greater than > b=6
a > b (returns false)
a=5
Less than or equal to <= b=6
a <= b (returns true)
a=5
Greater than or equal to >= b=6
a >= b (returns false)
Table 4.0 Commonly Used Visual Basic Comparison Operation
Logical Operators
 compare Boolean expressions and return a Boolean result.

Commonly Used Visual Basic Logical Operation

Logical Operation Operator Meaning

If expression is TRUE, then NOT expression is FALSE, or


Negation Not
If expression is FALSE, then NOT expression is TRUE

expression1 and expression2 is TRUE only if both expressions


Conjunction And
are TRUE, otherwise, the conjunction is FALSE

expression1 and expression2 is FALSE only if both expressions


Disjunction Or
are FALSE, otherwise, the conjunction is TRUE
Table 5.0 Commonly Used Visual Basic Logical Operation

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)

D. CONCATENATION OPERATORS AND STRING FUNCTION

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”

What values will the following statements return?


Len(z) = _____________________
x & “ “ & y = _____________________
y & “ and “ & z = _____________________
x & “ “ & z & “!” = _____________________

Direction: Identify the following questions. Write your answer in the answer sheet provided. [10 points]

1. Containers whose values once set, cannot be changed.


2. Containers whose values can be changed.
3. It denotes the possible values that a container can have.
4. It stores a number that contains decimal places.
5. These are used to perform any of the familiar arithmetic operations
6. It returns the length of the string.
7. It returns the character at a given position in the string.
8. It joins multiple strings into a single string.
9. It compares two expressions and return a Boolean value (True or False) that represents the relationship of
their values.
10. These are used to assign values on a containers or variables.

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 =

COMPUTER SCIENCE 10 - MODULE 12 AND 13


Name: ____________________________________________ Date:

____________________________________________

Teacher: __________________________________________ Grade & Section:

_________________________________

ANSWER SHEET
I. What’s More
Direction: Identification. [10 points]

1. 6.
2. 7.
3. 8.
4. 9.
5. 10.

II. What I Have Learned


Direction: Enumeration. [15 points]
1. 6. 11.
2. 7. 12.
3. 8. 13.
4. 9. 14.
5. 10. 15.

III. What I Can Do

Direction: Differentiate the terms constants, variables, and data types. [5 points]
IV. Assessment

Direction: Identify the result of the given questions. [10 points]


1. 6.
2. 7.
3. 8.
4. 9.
5. 10.

You might also like