Professional Documents
Culture Documents
Control Statements
and Functions
Lesson 2.4
Random Numbers
and Built-In
Functions
Objectives:
At the end of the lesson, you should
be able to:
1. describe
2. evaluate
3. generate
random numbers.
A Guessing Game
Let us construct a game wherein
the user tries to guess a number
held by the computer. To help the
user, the computer should prompt
the user to make a lower or a
higher guess if his/her guess is
incorrect. We shall need a form
with a text box named txtGuess
and a command button named
cmdOk, whose code will look
something like this:
continuation
A Guessing Game
You have probably noticed
something else-the MsgBox
statement. The MsgBox
statement produces a pop-up
message box that prompts the
user to click on a command
button (in the message box)
before he/she can continue.
continuation
BUTT
ONS
DISPL
AYED
Ok
button
Ok
and
vbOk
Cance
Canc
l
el
button
s
continuation
64
Name
d
Icon
s
Const
ant
vbCrit
ical
vbQu
estion
vbExc
lamati
on
vbInf
continuation
continuation
continuation
continuation
continuation
continuation
continuation
continuation
continuation
continuation
continuation
continuation
continuation
continuation
continuation
Int
(N)
Description
Gets the
absolute
value of N
Ex. Abs(3) =
Abs(-3) = 3
Rounds down
N to the
nearest
integer <=N.
Ex. Int(1.2) =
Int(1) =
Int(1.7) = 1
Int(-1.6) = Int(1.1) = Int(-2) =
continuation
continuation
continuation
continuation
Description
Converts the
strings
characters to
lowercase.
Ex.
LCase(Bob)
= bob
LCase(BOB)
= bob
Lcase(bob)
= bob
UC Converts the
continuation
continuation
continuation
continuation