-
April 15th, 2004, 07:54 AM
#1
Senior Member
First time programming
Im new to programming and am coding this project in VB 6.
I know that this code generates numbers from 1-9 only. Rnd chooses a decimal number in between 0,1. Int multiples this number by ten and rounds it. I want it to generate numbers at random in between 1-52. I feel lame but thought I could get advice or help, I know lamers use VB but C++ looks wicked hard. If I could get a list of functions like the ones you see here I would appreciate it and what If statement would you use?
Label1.Caption = Int(Rnd * 10)
Label2.Caption = Int(Rnd * 10)
Label3.Caption = Int(Rnd * 10)
Label4.Caption = Int(Rnd * 10)
Label5.Caption = Int(Rnd * 10)
Label6.Caption = Int(Rnd * 10)
End If
-
April 15th, 2004, 08:13 AM
#2
He, VB isn't lame, although I don't really like it (but that's just my opinion and I don't think at all VB is lame or something).
I don't know VB but can't you simply do:
Label1.Caption = Int(Rnd * 53)
The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me
www.elhalf.com
-
April 15th, 2004, 08:49 AM
#3
Senior Member
Yeah, I just did and it works, Thanx. I totally forgot to state two problems. Rnd picks decimal numbers in between 0,1. I dont want it to pick zero or .01. Last, I dont want identical numbers to be displayed in the labels at any given process. Have no idea what to do. Thanks for replies
-
April 15th, 2004, 09:30 AM
#4
you can just create some if-then-else contruction to avoid that.
The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me
www.elhalf.com
-
April 16th, 2004, 12:19 AM
#5
Getting rid of zero is easy as well. I'm not a VB programmer, but I think this should do:
Code:
Label1.caption = Int( Rnd * (num-1)) + 1
So if you wanted it between 1 and 10, you would put 9 instead of num-1 and it would generate a number between 0 and 9, and then add one to it, thus making it between 1 and 10:
Code:
Label1.caption = Int( Rnd * 9 ) + 1
Hope that helped.
ac
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|