Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How do you create random integers in VB 6.0?
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Darkmantis




PostPosted: Thu Dec 08, 2005 6:11 pm   Post subject: How do you create random integers in VB 6.0?

I am stuck on a game I am making because I have no clue how to make random integers. In turing it is Randint i: 1..6 but I don't know how it is in VB 6.0.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Dec 08, 2005 8:25 pm   Post subject: (No subject)

Rnd returns a random float.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Darkmantis




PostPosted: Fri Dec 09, 2005 6:57 am   Post subject: (No subject)

Rnd 6
If Rnd = 1 Or 4 Then
creature1.Left = creature1.Left + 300
End If
If Rnd = 2 Or 5 Then
creature1.Left = creature1.Left - 300
End If
If Rnd = 3 Or 6 Then
creature1.Left = creature1.Left
End If

im trying this code but its not working.
Tony




PostPosted: Fri Dec 09, 2005 9:35 am   Post subject: (No subject)

What values does Rnd return?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
pavol




PostPosted: Fri Dec 09, 2005 10:18 am   Post subject: (No subject)

anytime i've used the rnd function i store the randomized number in a variable like so: number = Int(Rnd * 6) and then check the number variable for the value
code:
If number = 5 then
'whatever
End If
Tony




PostPosted: Fri Dec 09, 2005 10:59 am   Post subject: (No subject)

Should be pointed out that Int(Rnd * 6) will return numbers from 0 to 5
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
pavol




PostPosted: Fri Dec 09, 2005 11:18 am   Post subject: (No subject)

if you don't want the zero then just add Int(Rnd *6)+1
Darkmantis




PostPosted: Sat Dec 10, 2005 10:28 am   Post subject: (No subject)

ok thx a lot guys Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: