a) Write a line of VBA code that generates a random number in the range [-11, 17
ID: 3829970 • Letter: A
Question
a) Write a line of VBA code that generates a random number in the range [-11, 17] and assigns the number to the variable r.
b) In the following lines, identify the range from which a random number will be generated:
i) x = rnd() * (13) + 3
ii) x = rnd() * (-5) + 2
iii) x = rnd() * 140 – 65
iv) x = 4 * (rnd() * 3) + 5
2) Briefly describe what action each of the following statements performs:
a) Dim FilmHeat() as Single
b) Dim TagName(32) as Single
c) FruitBat(x) = wings(a) – feet(b)^a
d) MsgBox WeaselSpleen(4)
e) conc = temp(i) + flow(i-1)
3) Write statement(s) that perform the following operations:
a) Create a static array Fire. Then size it to contain 5 elements, and populate each element with the string “BAD”.
b) Populate the n+1 elements of the integer array Ted with random numbers between -5 and 11
Explanation / Answer
Hi, I have solved first 2 question.
Please repost others in separate post.
1)
random = Int ((upperbound - lowerbound + 1) * rnd() + lowerbound)
in range: [-11, 17]
r = Int ((17 - (-11) + 1) * rnd() + -11)
= Int(29 * rnd() - 11)
Based on above formula, you can derive min and max range
i) x = rnd() * (13) + 3
13 = max - min + 1
min = 3
[3, 15]
ii) x = rnd() * (-5) + 2
-5 = max - min + 1
min = 2
[-4, 2]
iii) x = rnd() * 140 – 65
140 = max - min + 1
min = -65
[-65, 74]
iv) x = 4 * (rnd() * 3) + 5
x = rnd()*12 + 5
12 = max - min + 1
min = 5
[5, 16]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.