Powerful PowerPoint for Educators: Using Visual Basic for Applications to Make PowerPoint Interactive


Download 1.37 Mb.
Pdf ko'rish
bet149/191
Sana08.05.2023
Hajmi1.37 Mb.
#1442581
1   ...   145   146   147   148   149   150   151   152   ...   191
Bog'liq
2.2. Powerful PowerPoint For Educators

Ran 
dom 
ize
shuffles the cards. We
only need to do this once when we run the presentation, because the deck of
cards is very large. That is why we do this in our 
Ini 
tial 
ize
procedure.
Next, we want to get a random number. This is done with the 
Rnd
state -
ment. You could have a pro cedure that in cludes:
myRandomNumber = Rnd
MsgBox(myRandomNumber)
This will pop up a
MsgBox
with a ran dom number in it. The prob lem is that the
number that is generated is somewhere be tween 0 and 1. Nor mally, we want ran -
dom numbers that are positive integers (you know: 1, 2, 3, 4, 5, 6, . . . ). Have no
fear. That is where
Int
co mes in. 
Int
takes a real num ber and chops off ev ery-
thing after the decimal point. For ex ample,
Int(3.1415926)
re turns 3, and
Int(.4567)
re turns 0. We can gen erate a random number between 0 and 9
with:
myRandomDigit = Int(10 * Rnd)
By multiplying a number between 0 and 1 by 10, we get a number from 0 up to
9.99999999. By taking the 
Int
of that we get 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. We can
get a ran dom number in any range by us ing the following formula:
Ran dom Num bers 143


Int((upper – lower + 1) * Rnd + lower)
up 
per
is the big gest num ber you would want, and 
lower
is the small est num ber
you would want. For our 0 through 9 ex ample, we would have 
Int((9 – 0 +
1) * Rnd + 0)
or 
Int(10 * Rnd) + 0)
or just
Int(10 * Rnd)
. If we
wanted num bers from 1 to 100, we would have

Download 1.37 Mb.

Do'stlaringiz bilan baham:
1   ...   145   146   147   148   149   150   151   152   ...   191




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling