RM 17 - Working With Variables
RM 17 - Working With Variables
RM 17 - Working With Variables
Computer
I. Introduction
You often have to store values when you perform calculations with Visual Basic.
For example, you might want to calculate several values, compare them, and
perform different operations on them, depending on the result of the comparison.
You have to retain the values if you want to compare them. Visual Basic, just like
most programming languages, uses variables for storing values.
II. Objectives
At the end of the lesson, you should be able to;
1. define variables in Visual Basic 2010;
2. differentiate integer and string variables; and
3. cite example of the utilized variables in Visual Basic 2010.
III. Pretest
Answer the following questions;
1. What is a variable?
2. What is the difference between integer and string variable?
3. How do we utilized variables in Visual Basic 2020?
With Visual Basic and most programming languages, a variable is a storage area
of the computer’s memory which programs can manipulate.
Each variable in the Visual Basic has specific type. Each type determines the size
and layout of the variable’s memory; the range of variables to be stored within the
memory and the set of operations that can be applied in the variable.
Number1= 3
Number2= 5
Dim - short for dimension. This type of variable is a declaration or you are telling VB
that you are setting up a variable.
Example:
Aside from integer variables or numbers, variables can be names or texts. These
are called string variables. To set up a variable to hold a text, there’s a need to use As
String and not As integer.
FirstName = “Maria”
LastName = “Prado”
VB needs the two double quotation marks before it can identify the text or string.
Example:
FirstName = txtFirst.Text
LastName = txtLast.Text
MessageBox.Show(Name)
VI. Post-Test