Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
This code will generate random numbers, with the i...
Author:
Matt Smith
E-mail:
Click to e-mail author
Submitted:
8/7/2000
Version:
VB4
Compatibility:
VB4, VB5, VB6
Category:
Miscellaneous
Views:
8235
This code will generate random numbers, with the info: 1) How many values - txtValue 2) What the max is - txtMax 3) What the min is - txtMin 4) If they want duplicate random numbers, or not - OptionBoxes - Option1 = Double - Option2 = No Double
Declarations:
Option Explicit Dim HowMany As Integer Dim RndNum As Integer Dim Answer As String Dim I As Integer Dim Search As Integer
Code:
Private Sub cmdGenerate_Click() On Error GoTo Problem Randomize ReDim Ans(TxtValue) If Option1.Value = True And TxtMax - TxtMin < TxtValue Then MsgBox "It is impossible to generate that amount of random numbers without doubles." Exit Sub End If Answer = "" For HowMany = 1 To TxtValue 5 RndNum = Int(Rnd * TxtMax) + TxtMin If RndNum > TxtMax Then GoTo 5 If Option2.Value = True Then Ans(HowMany) = RndNum Else For Search = 1 To HowMany If RndNum = Ans(Search) Then GoTo 5 Next Search Ans(HowMany) = RndNum End If Next HowMany For I = 1 To TxtValue Answer = Answer & Ans(I) If I <> TxtValue Then Answer = Answer & ", " Next I MsgBox Answer Exit Sub Problem: MsgBox Err.Description End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement