USING DECISION
STATEMENTS
• One of the most useful tools for processing information in a
program is the use of conditional statements. These conditional
statements involve relational operators that could be either true
or false. These statements also involve logical operators.
• Relational operators can be also applied to letters and strings,
such as letter “a” is less than letter “b” and letter “h” is greater
than “g”. This is possible because all the characters on the
keyboard were assigned values of what commonly called the
ASCII code or American Association Code for Information
Interchange. ASCII is important especially if a validation is added
to the program.
ASCII Characters
• Most characters in the range of 0 to 31 are rarely
used. The following are the characters frequently
used.
CODE
0
9
10
13

CHARACTERS
Terminating null character
Tab
New line
enter
Code

Character

Code

Character

Code

Character

32

space

42

*

52

4

33

!

43

+

53

5

34

“

44

,

54

6

35

#

45

-

55

7

36

$

46

.

56

8

37

%

47

/

57

9

38

&

48

0

58

:

39

„

49

1

59

;

40

(

50

2

60

<

41

)

51

3

61

=
Code

Character

Code

Character

Code

Character

62

>

72

H

82

R

63

?

73

I

83

S

64

@

74

J

84

T

65

A

75

K

85

U

66

B

76

L

86

V

67

C

77

M

87

W

68

D

78

N

88

X

69

E

79

O

89

Y

70

F

80

P

90

Z

71

G

81

Q

91

[
Code

Character

Code

Character

Code

Character

92



102

f

112

p

93

]

103

g

113

q

94

^

104

h

114

r

95

_

105

i

115

s

96

`

106

j

116

t

97

a

107

k

117

u

98

b

108

l

118

v

99

c

109

m

119

w

100

d

110

n

120

x

101

e

111

o

121

y
Code

Character

122

z

123

{

124

|

125

}

126

~

127

Unused
IF THEN DECISION STATEMENT
• The IF Then selection performs an indicated action only
when the condition is TRUE unlike other conditional
statement it skipped an action if the logical test is not
met. This if… then statement is written on a single line:
If (condition) then (statement)
IF THEN structure does not require an end if or terminate
the conditional statement.
If age > 17 then lbldisplay.caption = “you are allowed to vote”

Logical Test

Action to be
executed if logical
test or condition is
true
Example
Private Sub Command1_Click ()
If Val (txtage) > 17 Then lbldisplay.caption = “You are
allowed to vote”
End Sub
• In the sample program, you will see how the action to be
executed is skipped if the logical test gives a false value. Age
17 gives a false value since the condition is true only if it is
more than 17.
IF Then Else

• An IF block statement is used to check
whether the logical test is true or false. It
will take the course of action based on
the result retrieved on the logical test.
YES

Execute
this action

If
condition
= true

NO

Execute
this action

• The computer evaluates the
logical test then it will decide
on the course of action it will
take, if it is yes it will execute
the action for true value else
it will execute the other
action. The if… then else
statement requires the same
number of end if the same as
number of if then used.
Structure

If condition/ logical test = true then
statement to be executed
Else
statement to be executed
End if
Example
If grade > 74 then
lbldisplay = “passed”
Else
lbldisplay = “failed”

End if

IF is paired
with an end if
If score > 74 then
lbldisplay = “you are qualified to the next
round”
Else
lbldisplay = “you are not qualified to the next
round”

End If
Nested If statement
• The if function is used to check one condition and
then execute the action for a true value, if not, it will
execute the other action. There are some cases
when there is a need to check more than one
condition. One must check one condition and then
another condition and then another and so on.
Method 1
If condition1 is true then
Execute statement1
Else if condition2 is true then
Execute statement2
Else
Execute else statement
End if
Method 2

If condition 1 then
Execute Statements
Else
If condition 2 then
Execute statements
Else

If condition 3 Then
Execute statements
Else
Execute statements
End If
End If
End if
In the structure, else if is not required to be
terminated with end if. Only the “If” statement
requires an end if. If three “if” statements are used,
they are terminated by three “end if” statements.
This implies that if the “if” statement is not needed
then it has to be terminated by “end if”. The logic
of this is that when the action of an “if” statement is
served already or no longer needed then it has to
be terminated by using end if.
example
If val (txtgrade) > = 90 Then
lbldisplay.caption = “A”

Elseif Val (txtgrade) > = 85 Then
lbldisplay.caption = “B”
Elseif val (txtgrade) > = 80 Then
lbldisplay.caption = “C”
Elseif val (txtgrade) > 75 Then
lbldisplay.caption = “D”
Else

lbldisplay.caption = “F”
End If

Using decision statements