Lesson Six
Lesson Six
Atupele Cairo 1
Language constructs : Data Types
◎ Data types specify the kind of data a variable can store, such as
numbers, text, or Boolean values.
◎ Dim myInteger As Integer
Dim myString As String
Dim myBoolean As Boolean
myInteger = 10
myString = "Hello, DIT!"
myBoolean = True
Atupele Cairo 2
Language constructs : Data Types
◎ Range variable: To use a range or a single cell as a variable,
first, you need to declare that variable with the range data type
(object variable).
◎ Dim r As Range
◎ Set r = Range("b16")
◎ r = 60
Atupele Cairo 3
Language constructs :Operators
◎ Operators perform operations on data (e.g., addition,
subtraction, comparison).
Dim num1 As Integer
Dim num2 As Integer
Dim result As Integer
num1 = 10
num2 = 5
result = num1 + num2 ' Addition
result = num1 - num2 ' Subtraction
result = num1 * num2 ' Multiplication
result = num1 / num2 ' Division
result = num1 Mod num2 ' Modulo
Atupele Cairo 4
Language constructs : Control
Statements
◎ Control Statements control the flow of program execution
(e.g., if statements, loops).
Dim num As Integer
num = 10
If num > 0 Then
MsgBox("Number is positive.")
Else
MsgBox("Number is non-positive.")
End If
Atupele Cairo 5
Language constructs : Comments
◎ Step 1: Click on the line where you want to insert a comment.
◎ Step 2: Type an Apostrophe( ' ) at the start of a line.
◎ Step 3: Write the comment you want. Step
◎ 4: Press Enter and you fill find the comment written to be
green.
Atupele Cairo 6
Thanks!
Atupele Cairo 7
Question
Write a program that add three
numbers
Write a program that identify
positive numbers
Add a comment in your
program
Atupele Cairo 8