Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

10

Technical-Vocational
Education (TVE)
COMPUTER
PROGRAMMING
Modules
Quarter 2 – Weeks 1 - 4
10
Technical Vocational
Education (TVE)
COMPUTER PROGRAMMING
Quarter 2 – Module 1
Starting a New Project
TVE 10 – ICT (Programming in Visual Studio 2010)
Alternative Delivery Mode
Quarter 2 – Module 1: Starting a New Project
First Edition, 2020

Republic Act 8293, section 176 states that: No copyright shall subsist in any work of the
Government of the Philippines. However, prior approval of the government agency or office
wherein the work is created shall be necessary for exploitation of such work for profit. Such
agency or office may, among other things, impose as a condition the payment of royalties.

Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names, trademarks, etc.)
included in this module are owned by their respective copyright holders. Every effort has been
exerted to locate and seek permission to use these materials from their respective copyright
owners. The publisher and authors do not represent nor claim ownership over them.

Published by the Department of Education - Schools Division Office of Makati City


OIC-Schools Division Superintendent: Carleen S. Sedilla CESE
OIC-Assistant Schools Division Superintendent: Jay F. Macasieb, DEM, CESE

Development Team of the Module


Writer: Arlene A. Purisima

Editor: Jean Tumaneng

Reviewer: Celedonia T. Teneza EdD

Layout Artists: Mayumi P. Realosa EdD , Maria Fe M. Samares

Management Team:
Neil Vincent C. Sandoval
Education Program Supervisor, LRMS

Celedonia T. Teneza EdD


Education Program Supervisor, EPP/TLE/TVL

Printed in the Philippines by the Schools Division Office of Makati City


Through the Support of the City Government of Makati (Local School Board)

Department of Education – Schools Division Office of Makati City

Office Address: Gov. Noble St., Brgy. Guadalupe Nuevo


City of Makati, Metropolitan Manila, Philippines 1212
Telefax: (632) 8882-5861 / 8882-5862
E-mail Address: makati.city@deped.gov.ph
What I Need to Know

Hello, Grade 10 Learners! This module is designed to help you fully


understand the process of creating your first user interface using Visual Basic 2010.
Feel free to explore each part and accomplish each activity at your own pace.

This module is here to guide you through this lesson. In case you were not able
to follow and understand some instances, you can always go back to that part.

This module is divided into two (2) lessons namely:


Lesson 1:
a) Create a new project
b) Define user interface
c) Use button, label box and textbox
d) Change Properties
Lesson 2:
e) Writing the code
f) Save and Run the Program
g) Debug

After going through this module, you are expected to:


1. Define user interface and give its types
2. Define form
3. Add textbox, label box and button;
4. Design the form using Properties window;
5. Code the program;
6. Save the program; and
7. Run the program
8. Debug the program

What I Know

Direction: Choose the letter of the best answer. Write the chosen letter on a
separate sheet of paper.
1. Which of the following control is used to accept and display editable text?
A. Graphic C. Picture
B. Label D. Text
2. Which of the following form property is used to indicate the background color of
the form?
A. Background Color C. Form Color
B. Background Image D. Form Background Color
3. Which of the following control is used when you want to display text used for
labeling other controls and output?
A. Clock C. Textbox
B. Label D. Timer

1
4. Which of the following is the system by which the user interacts with the
computer?
A. Form C. Work Area
B. Layout D. User Interface

5. Which of the following property is used to indicate the text that will appear in
the button?
A. Caption C. Name
B. Format D. Text

Lesson

1 Creating a New Project

What’s In

Let us have a recap on our last module on Form Controls, Properties and
other concepts. Answer the guide questions.
1. What is a control?
2. Name at least 5 controls and give their functions.
3. How do we name controls?

What’s New

ACTIVITY 1: Can you name the following sites?

1. ____________________ 2. _____________________ 3. ________________________

Bet you are smiling because you easily identified those sites. The picture above
are the user interface of the products or services you visited. Do you know that a
good user interface is one reason you keep coming back to the page?

2
Today, as you create your first program in Visual Basic, you will learn how to
create a user interface using Visual Basic. This will be the start of a long but fun coding
in VB. Enjoy the process!

What is It

Start a New Project


1. On the Menu bar, click File and click New Project
2. A new Project window will appear
3. Select Windows Froms Application
4. Click ok

User Interface Defined


According to Merriam dictionary, user interface is a software that is designed to
allow a computer user to interact with the operating system of a machine or system
such as by selecting presented options or entering text commands. It contains a set
of components that allow the computer to communicate. It is also used by the
computer as a means of getting input from the user and showing the output of a
process resulting from a set of choices and actions that the user has made.
Types of User Interface
1. Graphical user interface (GUI) – is a type of user interface that uses graphics to
represent the input and output of the program.
2. Command line interface – a type of user interface that relies on textual input and
output. The entire display screen shows only characters, no images, and the input
is performed entirely with a keyboard or scanner.
3. Touch user interface – is a graphical user interface that uses touchpad or
touchscreen display as a combined input and output device
Form Defined
Designing the interface begins with a form. The form is the object that
primarily represents the program interface. It is used as a container of controls.
Common Form Properties
• Backcolor - sets the form background color.
• BorderStyle - determines the style of the form's border and the appearance of
the form.
• Font - this property specifies font type, style, size.
• Height- this is the height of the Form in pixels.
• Name - this is the actual name of the form.

• Text - The text, which will appear at the title bar of the form.

Things like buttons, textboxes, and labels are all things that you can add to your
Forms. They are known as controls and are kept in the Toolbox for ease of use.

Add Controls in the form


To add controls into the form, click and drag the control to the form. Another
way is to double click the control and it will be automatically be displayed in the form.

3
Changing the properties
All the Visual Basic Objects can be moved, resized or customized by setting
their properties. A property is a value or characteristic held by a Visual Basic object,
such as Text or Fore Color.
You can change the properties of an object by typing or selecting the values
from the Properties window.

Lesson
Create, Run and Save the Project
2
Writing a Code:
A Visual Basic Statement has a format of: objectname. property=value
Where:
objectname- refers to the object assigned name in the project.
property- refers to the associated property to be edited or changed in an
object.
value – is the assigned value for the corresponding property.
Example:
Form1.backcolor=vbBlue
lbldisplay.text = “Hello students”
Running the Project
There are several ways to run the program:
1. Click F5 from the keyboard
Or
2. Click the click the green play button in the toolbar
Or
3. In the debug menu, click start debugging

Saving the Project


1. On the Menu Bar, click File and click SAVE ALL
2. The Save Project Dialog Box will appear
3. Type the filename and click Browse to select the location where you would your
file to be placed
4. The Create directory for solution should remain checked under the name of your
project along with the sub folders and files that get automatically created in
the Visual Basic environment
5. Click Save

Debugging
Debugging is the process of finding the errors in the code and removing
these errors from the code. Program errors come in three forms: syntax, logic and
runtime errors.
1. syntax errors – refers to a character or string incorrectly placed in a command or
instruction that causes a failure in execution.

4
2. logic error – are those errors that prevent your program from doing what you
expected it to do.

3. runtime error - a problem that is encountered when a program is being executed.

What’s More

Activity 2:

Design a form with one label box and two buttons.

5
Activity 3:
From activity 2, set the properties of the form following the table below:

OBJECT PROPERTY VALUE


FORM1 Name frmexample
Text My First Activity
Backcolor Any color of your choice
Label1 Name lbloutput
Autosize False
Font Book Old Style
Font Style Bold
Size 14
ForeColor Any color of your choice
Text Empty
Button1 Name btndisplay
Text DISPLAY
Button2 Name bntexit
Text EXIT

Note: Add a code in Button 1 – “Hello Grade 10 students!”


Button 2 – the program will close/exit

What I Have Learned

Direction: Identify the following terms. Write your answers on the space provided.

___________ 1. The meaning of the acronym GUI


___________ 2. A control used for inputting text
___________ 3. The prefix used in labeling button
___________ 4. The control that the user can click to invoke an action
___________ 5. The system wherein the user can interact with the computer
___________ 6. The keyboard command to RUN the project
___________ 7. To save the project you need to select this to save project and form
___________ 8. Start debugging is under what menu?
___________ 9. The process of finding and checking or errors
___________ 10. This property specifies font type, style, size

What I Can Do

Activity 4: Create a form that will produce the interface below. Select the appropriate
control to produce the same output/appearance. Be creative and add colors to your
form.

Criteria:
Presentation: 50%
Content: 50%

6
Sample Output:

Note: In a long bond paper, draw the user interface and create a table for
changing the properties of the objects used.

Assessment

Direction: Choose the letter of the best answer. Write the chosen letter on a
separate sheet of paper.

1. What term refers to the object assigned name in the project?


A. Data C. Objectname
B. Property D. Value
2. Which of the following refers to a character or string incorrectly placed in a
command or instruction that causes a failure in execution?
A. debug C. logic error
B. error D. syntax error

3. What window is used to assignor change the properties of a particular object?


A. form window C. solution explorer window
B. properties window D. toolbox window

4. Which of the following refers to the type of user interface that uses graphics to
represent the input and output of the program?
A. IDE C. OOP
B. GUI D. RAD
5. What term refers to the assigned value for the corresponding property?
A. Information C. Object
B. Labelname D. Value

6. What control is used to add event to an object?


A. Button C. Radio button
B. Label D. Textbox
7. Which of the following property is used to indicate the text that will appear in the
button?
A. Caption C. Name
B. Label D. Text

7
8. Which of the following is the system by which the user interacts with the
computer?
A. Form C. Work Area
B. Layout D. User Interface
9. What is the correct format of writing a visual basic statement?
A. Objectname.property=value C. input.process=output
B. Data.property.value D. objectname+properties=value
10. Which of the following form property is used to indicate the background color of
the form?
A. Background Color C. Form Color
B. Background Image D. Form Background Color

11. What type of error does the illustration show?

A. Logic error C. Runtime error


B. Syntax error D. Windows error
12. Which of the following control is used to accept and display editable text?
A. Graphic C. Picture
B. Label D. Text

13. What is the keyboard command in running your program?


A. ALT + S C. F5
B. CTRL D. F10
+S
14. What is the object that primarily represents the program interface? It is used
as a container of controls.
A. Data C. Label
B. Form D. Text
15. What property is used to change the name the title bar of the form?
A. Caption C. Text
B. Label D. Title

8
10
Technical Vocational
Education (TVE)
COMPUTER PROGRAMMING
Quarter 2 – Module 2
Variables and Data Types
TVE 10– ICT (Programming in Visual Studio 2010)
Alternative Delivery Mode
Quarter 2 – Module 2: Variables and Data Types
First Edition, 2020

Republic Act 8293, section 176 states that: No copyright shall subsist in any work of the
Government of the Philippines. However, prior approval of the government agency or office
wherein the work is created shall be necessary for exploitation of such work for profit. Such
agency or office may, among other things, impose as a condition the payment of royalties.

Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names, trademarks, etc.)
included in this module are owned by their respective copyright holders. Every effort has been
exerted to locate and seek permission to use these materials from their respective copyright
owners. The publisher and authors do not represent nor claim ownership over them.

Published by the Department of Education - Schools Division Office of Makati City


OIC-Schools Division Superintendent: Carleen S. Sedilla CESE
OIC-Assistant Schools Division Superintendent/OIC-Chief, CID: Jay F. Macasieb, DEM, CESE

Development Team of the Module


Writer: Arlene A. Purisima
Editor: Jean Tumaneng

Reviewer: Celedonia T. Teneza EdD

Layout Artists: Mayumi P. Realosa EdD, Maria Fe M. Samares

Management Team: Neil Vincent C. Sandoval


Education Program Supervisor, LRMS

Celedonia T. Teneza EdD


Education Program Supervisor, EPP/TLE/TVL

Printed in the Philippines by the Schools Division Office of Makati City


Through the Support of the City Government of Makati (Local School Board)

Department of Education – Schools Division Office of Makati City

Office Address: Gov. Noble St., Brgy. Guadalupe Nuevo


City of Makati, Metropolitan Manila, Philippines 1212
Telefax: (632) 8882-5861 / 8882-5862
E-mail Address: makati.city@deped.gov.ph
What I Need to Know

Hello, Grade 10 Learners! This module is designed to help you fully


understand the Variables and its datatypes. Feel free to explore each part and
accomplish each activity at your own pace.

This module is here to guide you through this lesson. In case you were not able
to follow and understand some instances, you can always go back to that part.

Are you ready? Let us start.


The module is composed of one (1) lesson:
Lesson 1 – Variables and data types
After going through this module, you are expected to:
1. define variable;
2. give the different data types to describe the data to be hold by the variable; and
3. demonstrate the use of variables;

What I Know
Direction: Choose the letter of the best answer. Write the chosen letter on a
separate sheet of paper.
1. Which of the following is a temporary storage location for data in your program?
A. Constant
B. Memory
C. Operator
D. Variable

2. The following statement shows the function of a variable except:


A. Assign a short and easy to remember name
B. Holds information entered by the user
C. Stores the result of a specific calculation
D. Holds the data permanently

3. In VB 2002, it has been necessary for VB programmers to explicitly declare


variables before using them. The term explicit means ____.
A. Declare the variables and it’s data type before use
B. Simply by using them and without having to include a dim statement
C. Variables which are declared without specifying it’s type
D. When you make a variable directly without order it first

4. To declare a variable in Visual Basic 2010, type the variable name after the Dim
statement. What does the reserved word DIM mean?
A. Dimension
B. Diminish
C. Light color
D. Nothing, for formality sake only

1
5. Why do you need to declare variables?
A. To identify the name and the type of your variables
B. For easy retrieval of data
C. The compiler can set aside the memory needed to store the program
D. All of the above

Lesson

1 Variables and Data Types

To transform data into information, the computer uses program. We learn from
the previous discussion that data are raw facts that are converted into a useful
information. In programming, data are associated with two different concepts: variables
and da types.
In Visual Basic 2010, it is important to note the difference among variables,
constants and the different data types, for you to be able to write the correct codes in
your program.

What’s In

Review:
1. What is a variable?
2. What are the different data types in VB 2010?
3. Give some rules in naming variables.

What’s New

ACTIVITY 1:
In this time of pandemic, you are required to give your information on a sheet of
paper for contact tracing. Please complete the form below.

2
In programming, to process the data given by the user, they are stored in a
location called variable. This topic will be discussed later.

What is It

Variable Defined
According to Halvorson, in his book entitled Visual Basic 2010, a variable is a
temporary storage location for data in your program. You can use one or many variables
in your code, and they can contain words, numbers, dates, properties, or other values.
By using variables, you can assign a short and easy-to-remember name to each
piece of data you plan to work with. Variables can hold information entered by the user
at run time, the result of a specific calculation, or a piece of data you want to display on
your form. In short, variables are handy containers that you can use to store and track
almost any type of information.

Data Types Defined


Data type is defined as a set of values that can be used to represent data. It also
determines what type of operations can be applied to the data. The table below shows
the Visual Basic Data types and the corresponding range of values for each type.

DATA TYPE MEANING STORAGE ALLOCATION


boolean Yes/no or True or False 1 byte
char Used to declaring 2 bytes
character type
Currency Holds currency 8 byte
date Stores the calendar date 8 bytes
integer Whole numbers can be 4 bytes
zero, positive or negative
Single/double Numbers with floating 4 bytes/8 bytes
point
string Sequence of character Depends on implementing
platform

Variables that store numbers are called numeric data types:


Numeric data types can be divided into two categories:
• Some have decimal point
• Some store integer values

Text data is refered to as string of character


• Data entered by user is text data
• Used to display output (results of computation)
• String are not using computations

Rules in Naming Variables


A variable is identified by it’s variable name or identifier name. When you create
a variable name, keep in mind that each variable name must be unique and must
describe the data it will contain.
1. It must contain a combination of letters, numbers and underscore
(ex: A1, empname, school_addres)

3
2. It contain a number
(ex: age123456, age_123, grade_1)

3. It must start with a lowercase letter and include a naming convention that
describes the data type
(same with examples 1 and 2)

4. It must not contain more than 255 characters

5. It must not be a VB keyword or reserved word


(avoid VB reserved words like string, end, dim, val…)

Declaring a Variable
Before a variable can be used in the program, it must be defined first.
Variables are defined through the process of variable declaration.
Syntax:
Dim VariableName as Data Type
Where:

• Dim – means dimension, a reserved word that indicates that the line of code is a
variable declaration
• Variable Name – the name of the variable
• As Data Type – name of the data type
Examples:
Variable Explanation
Dim X as Integer Holding numeric values with a value of 0
Dim y as Integer = 20 Holding or storing a numeric value of 100
Dim remark1, remark2, Holding three empty string variables
remark3 as String
Dim remark1 = “ “ Holding an empty string
Dim remark2 = “Good day!” Holding a string value Good day!

Importance of Variables
Variables allow the program be written so that no matter what the actual data
is, the algorithm or solution still works. Rather than entering the data directly into
the program, the programmer uses variable to represent data.

What’s More

Activity 2:
Based on activity 1, name the data and assign a variable for each data. Please follow
the rules in naming a variable. Write your answer on the space provided.
Number 1 is given as an example.

4
Data Entry Assigned VariableName Example

1. Date of visit visit_date _________________ Sept 6, 2020

2. Time of visit ______________________________ ____________

3. Real Name ______________________________ ____________

4. Complete Address ______________________________ ____________

5. Mobile # ______________________________ ____________

6. Email Address ______________________________ ____________

Activity 3: Direction: Identify the following variables are valid or invalid variable
names. Write Valid if it is valid and Invalid if not.

________________ 1. 123x

________________ 2. End

________________ 3. Father’s_name

________________ 4. Last_school_attended20

________________ 5. Yearandsection

________________ 6. Average

________________ 7. Result4020

________________ 8. String

________________ 9. 143_gender

________________ 10. answer

5
What I Have Learned

Direction: Answer the following questions.


1. What is a variable and how important it is in programming?
_____________________________________________________________________________________

_____________________________________________________________________________________

2. Give the five rules in naming variables. Give example on each.


2.a ________________________________________________________________________

2.b _______________________________________________________________________

2.c _______________________________________________________________________

2.d _______________________________________________________________________

2.e _______________________________________________________________________

3. List down the different data types in VB 2010. Give example on each.

Data Type Example


________________________________ __________________________________

________________________________ __________________________________

________________________________ __________________________________

________________________________ __________________________________

________________________________ __________________________________

________________________________ __________________________________

What I Can Do

Activity 4:

Chose one (1) from the folowing:

#1. Let your school ID scanned or photocopied and paste in a short bond paper.
Then identify those data that needs to be represented by a variable. Assign a
valid variable name on each data.
#2. Scanned/Photocopy of your registration form (last school year).

#3. Scanned/Photocopy your electricity bill or water bill.

6
Note: You may use the Identification card, registration form from any member of your
family (if lost). You can also ask any member from your family for the sample electricity
or water bill.
Criteria:
Content – 50%
Presentation – 50%

Assessment
Direction: Choose the letter of the best answer. Write the chosen letter on a
separate sheet of paper.
1. What term is used to describe the type of data a variable may hold?
A. Data type C. Data Representation
B. Data Define D. Variable type

2. Which of the following shows that variable should have no special character
except underscore?
A. 123_sample C. samp1e123_
B. sample_123 D. sample$123

3. For the patient screening in the table below, what type of data represents answer
for a Yes or No questions?

A. Boolean C. Integer
B. Double D. Single

4. Which of the following is a temporary storage location for data in your program?
A. Constant C. Operator
B. Memory D. Variable

5. Visual Basic data types are divided into two categories these are __?
A. Character and String C. Label and text
B. Date and Time D. Numeric and Text

6. The following statement shows the function of a variable except:


A. Assign a short and easy to remember name
B. Holds information entered by the user
C. Stores the result of a specific calculation
D. Holds the data permanently

7
7. Which of the following text data is referred to as string of character?
A. some data have decimal points
B. some uses whole numbers
C. some data are used to display output
D. none of the above

8. In VB 2002, it has been necessary for VB programmers to explicitly declare


variables before using them. The term explicit means ____?
A. Declare the variables and it’s data type before use
B. Simply by using them and without having to include a dim statement
C. Variables which are declared without specifying it’s type
D. When you make a variable directly without order it first

9. Which of the following data type is used for storing dates?


A. Date C. String
B. Decimal D. Time

10. Exam grade, your height and weight, the number of students in a class, price
of goods and monthly bills are examples of what type of data?
A. Data C. Symbolic
B. Numeric D. Text

11. To declare a variable in Visual Basic 2010, type the variable name after
the Dim statement. What does the reserved word DIM mean?
A. Dimension C. Light color
B. Diminish D. Nothing, for formality sake only

12. Which of the following data type is used for storing whole numbers?
A. Char C. Integer
B. Double D. String

13. Why do you need to declare variables?


A. To identify the name and the type of your variables
B. For easy retrieval of data
C. The compiler can set aside the memory needed to store the program
D. All of the above

14. Variable has three components: data type, name and values. Which of the
following describes the values?
A. Names, string, date C. Information stored in a variable
B. Unique name for data D. Operator used

15. What is the only character accepted in naming variables?


A. Dollar ($) C. Percent (%)
B. Pus (+) D. Underscore ( _ )

8
10
Technical Vocational
Education (TVE)
COMPUTER PROGRAMMING
Quarter 2 – Module 3
Expression and Operators
TVE 10 – ICT (Programming in Visual Studio 2010)
Alternative Delivery Mode
Quarter 2 – Module 3: Expressions and Operators
First Edition, 2020

Republic Act 8293, section 176 states that: No copyright shall subsist in any work of the
Government of the Philippines. However, prior approval of the government agency or office
wherein the work is created shall be necessary for exploitation of such work for profit. Such
agency or office may, among other things, impose as a condition the payment of royalties.

Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names, trademarks, etc.)
included in this module are owned by their respective copyright holders. Every effort has been
exerted to locate and seek permission to use these materials from their respective copyright
owners. The publisher and authors do not represent nor claim ownership over them.

Published by the Department of Education - Schools Division Office of Makati City


OIC-Schools Division Superintendent: Carleen S. Sedilla CESE
OIC-Assistant Schools Division Superintendent/OIC-Chief, CID: Jay F. Macasieb, DEM, CESE

Development Team of the Module


Writer: Arlene A. Purisima
Editor: Jean Tumaneng

Reviewer: Celedonia T. Teneza EdD

Layout Artists: Mayumi P. Realosa EdD, Maria Fe M. Samares

Management Team: Neil Vincent C. Sandoval


Education Program Supervisor, LRMS

Celedonia T. Teneza EdD


Education Program Supervisor, EPP/TLE/TVL

Printed in the Philippines by the Schools Division Office of Makati City


Through the Support of the City Government of Makati (Local School Board)

Department of Education – Schools Division Office of Makati City

Office Address: Gov. Noble St., Brgy. Guadalupe Nuevo


City of Makati, Metropolitan Manila, Philippines 1212
Telefax: (632) 8882-5861 / 8882-5862
E-mail Address: makati.city@deped.gov.ph
What I Need to Know

Hello, Grade 10 Learners! This module is designed to help you fully


understand the Expressions and the different operators. Feel free to explore each part
and accomplish each activity at your own pace.

This module is here to guide you through this lesson. In case you were not able
to follow and understand some instances, you can always go back to that part.

This module is divided into two (2) lessons namely:


Lesson 1: Expressions
a) Expression
b) Types of Operators
c) Order of Precedence

Lesson 2: Assigning Values to Variable


d) Using Variables
After going through this module, you are expected to:
1. Define expression;
2. Differentiate operator from operand;
3. Identify the types of operators;
4. Evaluate expression following the order of precedence and
5. Create a program applying expressions using variables

What I Know
Direction: Choose the letter of the best answer. Write the chosen letter on a
separate sheet of paper.
1. Which of the following symbol does not represent an arithmetic operator?
A. + C. >
B. - D. /

2. What is the meaning of the following expression: a+=7?


A. a+7 C. a=a+7
B. a=7 D. a=1+7

3. What is the type of operator to compare values?


A. Arithmetic operator C. Logical operator
B. Assignment operator D. Relational operator

4. Which of the following is the set of values that can be used to represent data?
A. Data type C. Operand type
B. Expression Type D. Variable types

5. What is a keyword that is used in declaring variables?


A. Declare C. Initialize
B. Dim D. Var

1
Lesson

1 Expression and Operators

What’s In

Recall module 2: Answer the following questions:


1. Give the steps in creating a new project.
2. What is a user interface?
3. How do you save your project?

What’s New

ACTIVITY 1:
WORD SEARCH

____________________________________________________________________________________
DIM ARITHETIC PRECEDENCE OPERATOR
VARIABLE EXPRESSION
RULES: Find and circle the words. The words are written on one straight line
from right to left, vertically, horizontally, and diagonally.

Did you find all the words? If your answer is yes, then you have a keen
eyesight! You are now ready to proceed to the discussion of our next
lesson.

2
What is It

Expression Defined
In computer programming, an expression is a combination of operands and
operators that can be evaluated to a single value. An expression must have at least
one operand but may not have any operator.

Example:
Average as double;
Average = 75.00

Here, 75.00 is an expression. Also, average = 75.00 is an expression too.

Another example:

Dim X, Y , sum as integer


Sum = x + y
If (sum>=100) then
Textbox1.text = “Congratulations”
Endif

Here, if sum>=100 is an expression, that returns a boolean value. “Congratulations”


is also an aexpression.

When an expression is evaluated, the expression returns a value of a specific


data type. An expression is made up of two elements: the operands and the operators.
The operands are made up of variables that represent the value to be manipulated,
while the operator is a code that performs an operation on one or more operands.
Operators transform the values of an operand by performing the mathematical
calculations, comparisons or other operations.

price * quantity
expression
operand

operator

Visual Basic provides the following types of operatos:


• Arithmetic operator – performs addition, subtraction, multiplication and
division
• Relational operator – also known as comparison operators
( >, <, >=, <=, =, <>)
• Logical operator – operator that compares two or more Boolean expression
and returns a boolean value (not, or, nor)

3
Arithmetic Operators

OPERATOR SYMBOL DESCRIPTION EXAMPLE (x=7)


ADDITION + Adds two or more X+3 =10
numbers
SUBTRACTION - Subtract two numbers X-3 = 4
MULTIPLICATION * Multiplies two numbers X*3 = 21
EXPONENTIATION ^ Raises the number to X^4 = 2401
specified power
Divides the two X/3 = 2.33
DIVISION / numbers and returns
the quotient with
decimal place

Divides the two X\3 = 2


INTEGER DIVISION \ numbers and returns
the quotient in integer
format

Divides the two X Mod 3 = 1


MODULUS DIVISION mod numbers and returns
the remainder

Order of Precedence (PEDIMA Rule)


The order of precedence refers to the sequence in which operators are evaluated.
It ensures that the given expression will return the same value every time it is evaluated.

ORDER OF OPERATOR SYMBOL/S


PRECEDENCE
1st Parenthesis ( )
2nd Exponentiation ^
3rd Division and Multiplication /, *
4th Integer Division \
5th Modulus Division mod
6th Addition and Subtraction +, -

Example1: x= 15/3 * 3^2 + (2*3+12)

Follow the PEDIMA rule:

= 15/3 * 3^2 + 18 (parenthesis)


= 15/3 * 9 + 18 (exponentiation)
= 5 * 9 + 18 (division)
= 45 + 18 (multiplication)
x = 63 (addition)

Example2: a=10 + 3 ^ 2 mod 4 \ 3 * 2 / (7-4)

Follow the PEDIMA rule:


= 10 + 3 ^ 2 mod 4 \ 3 * 2 / 3 (parenthesis)
=10 + 9 mod 4 \ 3 * 2 / 3 (exponentiation)
=10 + 9 mod 4 \ 2 (division, multiplication, following left to
right rule)
=10 + 9 mod 2 ( integer division)
=10 + 1 (modulus division)
a = 11 (addition)

4
Assignment Operators
The operator that is used to assign or store a value to variable. It is one of the
most commonly used operators in many programming language.
Operator Example (x=6) Meaning
= X=6 Move the value 6 to the
variable x
+= X+=6 X=X+6
-= X-=6 X=X-6
*= X*=6 X=X*6
/= X/=6 X=X/6
\= X\=6 X=X\6
^= X^=6 X=X^6

Lesson
Assigning Values to Variable
2
In Visual basic, one needs to declare the variables before using them by assigning
names and data types. If you do so, the program will produce an error. They are
normally declared in the general section of the codes window. Use Dim keyword to
declare variable and allocate storage space for it in memory.

Syntax:

Dim variable as data type


Examples:

Dim x as Integer
Dim a, b, c as Integer
Dim ave as Double
Dim studname as String

Assigning Values to Variable


After declaring variables, you can assign values to those variables. The general
format of an assignment is
Variable = Expression
Num = 10
Password=”1234”
Label1.visible = true

Place the Data in the VariableNum1=val(txtnum1.text)


Name=val(txtnum2.text)
Or
Num1=txt1.text
Name=txtname.text

Caculate the result/Display using variable


Calculate the SUM:
Sum= num1 + num2
Sum = text1.text + text2.text
Sum = val(text1.text) + val(text2.text)

Display the Result

lbldisplay.text=sum
txtresult.text = text1.text + text2.text

5
Example Application Using Arithmetic Operator

Steps:
1. Design the user interface
2. Set the properties of each object (from the Properties window)
Change the following:
Name
Text
Back color
Font
Font Color
3. Add the Code

Double Click the SUM Button then write the ff. code
Private sub btnsum_click()
Dim a, b, sum As Integer
a = Val(txtuna.Text)
b = Val(txtpangalawa.Text)
sum = a + b
txtsagot.text = sum
end sub

4. Run (F5) / Debug


5. Save your project

What’s More

Activity 2:
Direction: Name the following mathematical sign. Write your answers on the
space provided.

______________ 1. * ______________ 6. ( )
______________ 2. > ______________ 7. Not
______________ 3. <= ______________ 8. +
______________ 4. / ______________ 9. Mod
______________ 5. Or ______________ 10. =

Activity 3:
Direction: Solve each expression following the hierarchy of operations. Write your
step by step calculation on each line.

1. x= 4 * 10 * 10 + 6 * 10 + 14
Step 1. ___________________________________________
Step 2. ___________________________________________
Step 3. ___________________________________________

6
Step 4. ___________________________________________
Step 5. ___________________________________________

2. z= 7 * 5 + (25 * 4) + 14 * 2 Mod 4 + 10 / 2

Step 1. ___________________________________________
Step 2. ___________________________________________
Step 3. ___________________________________________
Step 4. ___________________________________________
Step 5. ___________________________________________
Step 6. ___________________________________________
Step 7. ___________________________________________
Step 8. ___________________________________________

What I Have Learned

A. Arrange each of the flowing operations according to the order that a computer
follows to solve an expression. Write your answer on the space provided. (1 to 5)
________ 1. Addition and subtraction
________ 2. Modulus Division
________ 3. Parenthesis
________ 4. Integer Division
________ 5. Exponentiation

B. TRUE or FALSE
________ 6. Double is a data type that holds whole numbers
________ 7. +, -, * and / are considered as relational operators
________ 8. Logical operator are operators that compares two or more Boolean
expression and returns a boolean value
________ 9. Order of precedence refers to the sequence in which operators are
Evaluated
________ 10. In VB, the expression Sum= num1 + num2 is same as
Sum = text1.text + text2.text

What I Can Do

Direction: Create a program that will take two numbers as input then display the
result depends on the action selected by the user.

Note: In a long bond paper, draw the user interface and create a program on each
event button.
Criteria: Presentation – 50%
Accuracy - 50%

7
Assessment

Direction: Choose the letter of the best answer. Write the chosen letter on a
separate sheet of paper.
1. What term refers to the combination of operators and operands that
evaluates to a single value?
A. Data C. Expression
B. Information D. Variable
2. Which of the following refers to a named storage that temporarily resides in the
computer memory?
A. Data C. Expression
B. Operator D. Variable

3. Which of the following is a valid statement?


A. average = a + b + c/3 C. average = (a+ b + c/3)
B. average = (a+ b + c)/3 D. average = (a*b*c)/3

4. What is the value of the following expression if variable x = 2 and y = 3


(x *2) < (y + 5)?
A. 12 C. FALSE
B. TRUE D. NULL
5. Which of the following are made up of variables that represent the value to be
manipulated?
A. Operands C. Symbols
B. Operator D. Variable

References:

https://www.programiz.com/csharp-programming/expressions-statements-blocks
https://www.computerhope.com/jargon/o/order-of-operations.htm
Visual Basic 2010 Programming, H&D Information Technology, Inc. pp 123-124.

8
10
Technical Vocational
Education (TVE)
COMPUTER PROGRAMMING
Quarter 2 – Module 4
Working with Strings
TVE 10 – ICT (Programming in Visual Studio 2010)
Alternative Delivery Mode
Quarter 2 – Module 4: Working with Strings
First Edition, 2020

Republic Act 8293, section 176 states that: No copyright shall subsist in any work of the
Government of the Philippines. However, prior approval of the government agency or office
wherein the work is created shall be necessary for exploitation of such work for profit. Such
agency or office may, among other things, impose as a condition the payment of royalties.

Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names, trademarks, etc.)
included in this module are owned by their respective copyright holders. Every effort has been
exerted to locate and seek permission to use these materials from their respective copyright
owners. The publisher and authors do not represent nor claim ownership over them.

Published by the Department of Education - Schools Division Office of Makati City


OIC-Schools Division Superintendent: Carleen S. Sedilla CESE
OIC-Assistant Schools Division Superintendent/OIC-Chief, CID: Jay F. Macasieb, DEM, CESE

Development Team of the Module Arlene


Writer: A. Purisima
Editor: Jean Tumaneng

Reviewer: Celedonia T. Teneza EdD

Layout Artists: Mayumi P. Realosa EdD, Maria Fe M. Samares

Management Team:
Neil Vincent C. Sandoval
Education Program Supervisor, LRMS

Celedonia T. Teneza EdD


Education Program Supervisor, EPP/TLE/TVL

Printed in the Philippines by the Schools Division Office of Makati City


Through the Support of the City Government of Makati (Local School Board)

Department of Education – Schools Division Office of Makati City

Office Address: Gov. Noble St., Brgy. Guadalupe Nuevo


City of Makati, Metropolitan Manila, Philippines 1212
Telefax: (632) 8882-5861 / 8882-5862
E-mail Address: makati.city@deped.gov.ph
What I Need to Know

Hello, Grade 10 Learners! This module is designed to help you fully


understand the String concatenation and string functions. Feel free to explore each
part and accomplish each activity at your own pace.

This module is here to guide you through this lesson. In case you were not
able to follow and understand some instances, you can always go back to that part.

Lesson 1: Working with Strings


Lesson 2: String Functions
After going through this module, you are expected to:
1. Define non-numeric data types
2. Define string and concatenation;
3. Define concatenation ;
4. Compare the different string functions and
5. Use string functions

What I Know
Direction: Choose the letter of the best answer. Write the chosen letter on a
separate sheet of paper.
1. What is the process of combining two or more strings into one single string?
A. Addition C. Concatenation
B. Combination D. Merging

2. What is a string function that will convert “programming” to “PROGRAMMING”?


A. LCase C. Mid
B. Len D. Ucase

3. What is the output of the command Len(“God will make a way")?


A. 15 C. 20
B. 19 D. 22

4. What command is used to extract X2 characters from the middle of the string
word, beginning with the character number x1?
A. Len C. Mid
B. LCase D. Middle

5. Given the four string variables,


word1 = “Visual Basic word3= “is a programming language”
word2=”is a third generation language” word4 = “is an OOP language”

What is the output of the command: word1 & " " &word4?
A. Visual Basic is a programming language
B. Visual Basic is a third generation language
C. Visual Basic is an OOP language
D. Visual Basic is a programming language, third generation language, OOP
language

1
Lesson

1 Working with Strings


During our discussion about data type, we learnt that character data type deals
with a single character and you can assign any character from your keyboard to a
character type variable.

Now, let's move a little bit ahead and consider a situation where we need to store
more than one character in a variable.

What’s In

Let us have a quick recap on our last module on Expressions and operators by
answering these questions.

1. What are the different types of operators?


2. How do we evaluate expression using order of precedence?
3. Give the syntax or format in assigning value to text object.

What’s New
ACTIVITY 1: Classify the following information whether Numeric or Non-Numeric
Write a short explanation why they are classified as that.

NUMERIC NON- NUMERIC

2
What is It

Non-Numeric Data Types


Non-numeric data types are data that cannot be manipulated mathematically
using standard arithmetic operators. The non-numeric data comprises text or string
data types, the data datatypes, the boolean data types that store only two values (true
or false), object data type and variant data type.

STRINGS are used to represent non -numeric information such as gender, name,
address, and the like. They are always entered in code inside quotation marks.
In programming, a string is a single unit of data that made up of a series of
characters that includes letters, digits and alphanumeric symbols It is treated as the
String data type. It is non-numeric in nature, though it might consist of numbers.
Everyday life examples of strings are names, addresses, gender, cities, book titles, phone
numbers, email addresses and more. In Visual Basic 2010, you can manipulate strings
by writing code to process characters like sentences, words, text, alphanumeric
characters and more.

Task that you can accomplish when working with strings:


• To separate that first and last names from a string representing a person’s full
name
• Convert string to all upper case
• Concatenate or join two strings
• Display a number of currency format
• Replace some of the string with another string

String CONCATENATION
In VB, you can use either the ampersand (&) or the Plus sign (+) as a
concatenation operator.

Concatenation is the process of combining two or more strings into a single string.

String Manipulation Using + and & signs


In Visual Basic 2010, you can manipulate strings using the & sign and the +
sign, both perform the string concatenation which means combining two or more
smaller strings into larger strings. For example, we can join “Visual” and “Basic” into
“Visual Basic ″ using:

Word1 = “Visual”
Word2 = “Basic”
Then the string expression
Word1 & “ “ + Word2

Output: Visual Basic

Note: You can also add string of text to complete your message.
“ “ are used to add space.

Example: “Hello students!!” & “ “ + “ Welcome to” & “ “ + word1 & “ “ + word2

3
Example Application

CODE:

Private Sub btnconcatenate_Click()


Dim w1, w2, w3 As String
w1 = txtw1.Text
w2 = txtw2.Text
w3 = txtw3.Text
lbldisplay.Text = w1 & " " + w2 & " " + w3

End Sub

See the difference

CODE:

Private Sub btnconcatenate_Click()


Dim w1, w2, w3 As String
w1 = txtw1.Text
w2 = txtw2.Text
w3 = txtw3.Text
lbldisplay.Text = "Hello students!!" & " " +
" Welcome to" & " " + w1 & " " + w2 & " " + w3
End Sub

Lesson

2 String Function
The flexibility of using Visual Basic function in terms of manipulating string
includes searching a string, changing the case of the string, determining the reverse
of the string, position on the string…

Library Functions in String Variables

FUNCTION APPLICATION/SYNTAX DESCRIPTION

Len • Len(string) This used to display the length or


Len(“Computer”) number of characters of the string word.
Output: 8
LCase • Lcase(string) Used to display the lowercase equivalent
Lcase(“CoMPuter”) of the string.
Output: computer
UCase • Ucase(string) Used to display the Uppercase equivalent
UCase(“CoMPuter”) of the string.
Output: COMPUTER
Left • Left(string, Returns a string containing a specified
length) number of characters from the left side of
Left(“computer”,3) the string.
Output: com

4
Right • Right(string, Returns a string containing a specified
length) number of characters from the right side
Right(“computer”,3) of the string.
Output: ter
Mid • Mid(string, start, Used to extract X2 characters from the
length) middle of the string word, beginning with
Mid(“computer”, 4,2) the character number x.
Output: pu
InStr • InStr([start],string Returns the position of the first
, search) occurrence of one string within another.
InStr(1, “compute” ,”m”)
Output: 3
StrReverse • StrReverse(string) Returns the position of the string in the
reverse order.
StrReverse(“desserts”)
Output: stressed

Sample Program using String Functions

LEN Ucase
1. Dim word As String Dim word As String
Dim z As Integer Dim z As String
word = "programming" word = "programming"
z = Len(word) z = UCase(word)
Label1.Text = z Label1.Text = z

LCase Left
Dim word As String Dim word As String
Dim z As String Dim z As String
word = "PROGRAmming" word = "programming"
z = LCase(word) z = Microsoft.VisualBasic.Left(word,7)
Label1.Text = z Label1.Text = z

Right Mid
Dim word As String Dim word As String
Dim z As String Dim z As String
word = "programming" word = "Programming"
z= z = Mid(word, 4, 4)
Microsoft.VisualBasic.Right(word, 4) Label1.Text = z
Label1.Text = z

Instr StrReverse
Dim z As String Dim word As String
z = InStr("The quick brown fox Dim z As String
jumps over the word = "desserts"
lazy dog", "o") z = StrReverse(word)
Label1.Text = z Label1.Text = z

5
What’s More

Activity 2: String Concatenation

Do as indicated:
1. Create a new project
2. Design a user interface similar to the output below.

3. Change the object properties on the properties window as shown below.

Object Property Value


Label1 Name Ex: lblname1
Text Name1:
Label2 Name
Text
Label3 Name
Text
Textbox1 Name
Text
Textbox2 Name
Text
Textbox3 Name
Text
Taxtbox4 Name
Text
Button1 Name
Text

4. At the code editor, type the code for the event in button1.

Activity 3: String Functions


Create a program given the interface and sample output:

6
After the user click the string function button, the output will be displayed in the
textbox.
Output:

What I Have Learned

A. Give the syntax for the following string functions:


1. Ucase _______________________________________________________________________
2. Mid _______________________________________________________________________
3. Strreverse _____________________________________________________________________
4. Right _________________________________________________________________________
5. Lcase _________________________________________________________________________

B. Identification:
1. It is the process of combining two or more strings into a single string.
2. The data type used to display non-numeric values like address, name, surname…
3. This used to display the length or number of characters of the string word.
4. Used to display the Uppercase equivalent of the string.
5. Used to display the lowercase equivalent of the string.

What I Can Do

Direction: Write a program that will display the concatenated string values after
clicking the concatenate button.
User Interface:
Output:

7
Note: In a long bond paper, draw the user interface and create a program on the
concatenation button.
Criteria: Presentation – 50%
Accuracy - 50%

Assessment

Direction: Choose the letter of the best answer. Write the chosen letter on a
separate sheet of paper.
1. Which of the following used the correct syntax of right command?
A. Microsoft.Visual Basic.Right (“String Function” 7)
B. Microsoft.VisualBasic.Right (“String Function” 7)
C. Microsoft.Visual_Basic.Right (“String Function” 7)
D. None of These

2. Which of the following are used to represent non -numeric information such as
gender, name, address, and the like?
A. Boolean
B. Character
C. Expression
D. String

3. What string function returns the position of the string in the reverse order?
A. Inverse
B. Reverse
C. StrReverse
D. StringReverse

4. What is the output of Mid(“Good luck ” 6, 4)?


A.Good
B.luck
C.ood
D.uck

5. Which of the following is used to display the Uppercase equivalent of the string?
A. Mid
B. LCase
C. Len
D. Ucase

Reference:
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-
guide/language-features/operators-and-expressions/concatenation-operators

You might also like