making a random number appear in a label

Started by
7 comments, last by Twisted Puppet 20 years, 10 months ago
What would be the code for a random number, lets say 1-5 to appear in a label? There is a fine line between genious and insane
There is a fine line between genious and insane
Advertisement
Which language?
~"What''s this red button do?"
O duh I forgot that.... it is C++, I am using "Microsoft Visual Basic 6.0" any help?
There is a fine line between genious and insane
quote:
it is C++, I am using "Microsoft Visual Basic 6.0" any help?


WTF?
Microsoft Visual Basic 6.0 I guess.... I haven''t been programming for very long
There is a fine line between genious and insane
Dim iUpper As Integer
Dim iLower As Integer

iUpper = 5
iLower = 1

iRoll = Int((iUpper - iLower + 1) * Rnd + iLower)

labelname.caption = iRoll


That should work. Been awhile since I did that in VB though

~"What''''s this red button do?"
~"What''s this red button do?"
Thank you psyberia, your help is greatly appreciated!
There is a fine line between genious and insane
One more thing I forgot to add. You have to put Randomize before the line where you are using Rnd if you plan on using this more than once. (IE, generating random damage or whatever).

[edited by - Psyberia on June 4, 2003 9:31:22 PM]
~"What''s this red button do?"
Or in in the Form_Load() procedure you could just put Randomize Timer. They both work though, up to you

This topic is closed to new replies.

Advertisement