|
-
Feb 25th, 2006, 01:17 PM
#1
Thread Starter
Hyperactive Member
Genorating ramdom numbers
Hello,im wondering how i can genrate 11 numbers all beggin with 7 example
i click genrate it says in text1 795656532 click again it says 7139900,many thanks
-
Feb 25th, 2006, 01:25 PM
#2
Re: Genorating ramdom numbers
If you always want large numbers like that you could do it like this:
VB Code:
sNum As String
Dim i As Integer
Dim iMax As Integer
Randomize
sNum = "7" '<- You wanted it to start with a 7
iMax = Int(Rnd * 4) + 4 '<- iMax will be a number between 4 and 7
For i = 1 To iMax '<- Loop from 1 to (4-7)
sNum = sNum & Int(Rnd * 10)
Next
'sNum will now be a 5 to 8 digit number starting with a 7
Text1.Text = sNum
-
Feb 25th, 2006, 01:32 PM
#3
Thread Starter
Hyperactive Member
Re: Genorating ramdom numbers
i want it to genrate 16 numbers each time, i tried changing iMax = Int(Rnd * 9) + 9 to diffrent things etc,and it genrators ramdom amound of numbers like
769591628176
729741547050
7660505292077
some are longer than overs i just want 16 in total many thanks any ideas?
-
Feb 25th, 2006, 01:37 PM
#4
Re: Genorating ramdom numbers
Sorry, your first post showed two numbers of different lengths so I thought that was what you wanted. Simply skip the iMax line and change the loop to:
VB Code:
'Replace iMax with 15 to generate a 16 digit number (with the initial 7)
Dim i = 1 To [b]15 [/b]
-
Feb 25th, 2006, 01:45 PM
#5
Thread Starter
Hyperactive Member
Re: Genorating ramdom numbers
sNum As String
Dim i As Integer
Dim iMax As Integer
Private Sub Command1_Click()
Randomize
sNum = "7" '<- You wanted it to start with a 7
iMax = Int(Rnd * 4) + 4 '<- iMax will be a number between 4 and 7
For i = 15 To iMax '<- Loop from 1 to (4-7)
Dim i = 1 To 15
sNum = sNum & Int(Rnd * 10)
Next
'sNum will now be a 5 to 8 digit number starting with a 7
Text1.Text = sNum
End Sub
***
-
Feb 25th, 2006, 01:53 PM
#6
Re: Genorating ramdom numbers
Sorry, I accidently typed Dim but I meant For.
VB Code:
sNum As String
Dim i As Integer
Randomize
sNum = "7" '<- You wanted it to start with a 7
For i = 1 To 15
sNum = sNum & Int(Rnd * 10)
Next
'sNum will now be a 5 to 8 digit number starting with a 7
Text1.Text = sNum
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
|
Click Here to Expand Forum to Full Width
|