-
random number
Hi
I want to make a txtbox where a number between 1 to 456 to apear continuously, until I press a button.
Could you help me with an exemple?
Thanks and best regards
-
Example
There are at least 100,000,000 ways to do this, here is one.
Create a project with 1 Form
add two buttons and a timer
Set timer property:
enabled = False
interval = 1000
Set Command1:
Caption = &Start
Set Command2:
Caption = Sto&p
In the code paste:
Code:
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim z As Integer
z = Int((Rnd * 456) + 1)
If z <= 456 Then
Text1.Text = z
End If
End Sub
Hope this helps
Newtonberry.com
Last edited by Newtonberry; 11-08-2010 at 03:48 PM.
Reason: Removed unused code
-
Thanks, but I want to do a number (in txtxbox or label) which it is changes continuu until I press the button.
I want to make this for draw a winer, because the number represent a customer bil...
Thanks in advance
Last edited by comandor; 11-09-2010 at 01:46 AM.
-
Did you try the example posted by Newtonberry?
His code works just fine for me.
-
Thanks, the code is OK, but I have a lot a problems...Now, I understand that I have a lot of customer bils and each bil has a number which can be 2345, 2346 or 2399, 3278. So, here is my problem, there are not consecutive numbers.
I try to make 4 labels, in each of them to apear a digit number (eg. 2,3,4,5), I place 4 Timer on form, and I got stuck...
Well, I think there is 2 ways to solve this:
-to put the numbers in a table and when I press the button each number must be split in 4 digit number...
-to rule continuu all the number in a same textbox or label and when I press button the numbers stop. I don't know how can I do this, please give me a help.
Thanks
-
Not sure
I'm not exactly sure what your asking but maybe this will help.
Code:
Private Sub Timer1_Timer()
Dim z As Integer
z = Int((Rnd * 456) + 1)
If z <= 456 Then
Text1.Text = z
End If
End Sub
In the above code Rnd is a Random number. We multiply that number by our upper limit number 456. Then we add 1, this is our lower limit. Not exactly what happens but close enough.
Then we check that our number isn't above 456, because 456+1=457 we don't want that. "Yes, had we put 455 as our multiplier that would had solved that.
So if we want single digit numbers we just change 456 to 8. Then our example would give numbers 1-9. If we take out our +1 from the function we get 0-9.
Hope that isn't confusing.
-
Thanks, now is better...Your descriptions help me more, thanks again!
Similar Threads
-
By FilthyGnome in forum C++
Replies: 1
Last Post: 11-05-2008, 09:41 AM
-
Replies: 2
Last Post: 12-07-2007, 06:17 PM
-
By QuinnMal in forum Java
Replies: 0
Last Post: 07-05-2007, 11:12 AM
-
Replies: 18
Last Post: 12-13-2006, 03:49 PM
-
By cmvw in forum VB Classic
Replies: 7
Last Post: 06-28-2006, 10:04 AM
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|