Home > Software engineering >  Vba to achieve 6 1 don't overlap permutation and combination
Vba to achieve 6 1 don't overlap permutation and combination

Time:10-17



Want to use vba to realize the double chromosphere seven figures of choice, and do not overlap, how to implement? Save and generate to excel in, thank you!

CodePudding user response:

Please refer to: (lotteries have risk, investment should be cautious )
 Option Explicit 
Sub test ()
Dim iDic As New Dictionary, w1 As String, ww
Randomize 'random initialization
"' red ball 1-33 arbitrary 6
Do
W1=Format $(CInt (Rnd * 33) + 1, "0 #")
If Not iDic. The Exists (w1) Then iDic (w1)="0"
If iDic. Count=6 Then Exit the Do
Loop
Taking 1 'blue ball
W1=Format $(Int (Rnd * 16) + 1, "0 #")
"' output
The Debug. Print the Join (iDic Keys, ", ") & amp; "--" & amp; W1
IDic. RemoveAll 'empty dictionary
End Sub

CodePudding user response:

You said "no coincidence" refers to the random generation of a note no repeat number is the number?
To save to Excel, the said too vague...
Is the documents? Or create new document after a set number?
Every time how much of an note number? Is fixed, or a range of random? Before their input number or produce?

Alas, still see a note of the number of the first:
 Private Sub Command1_Click () 
Dim sOut As String
Dim aBuf (), As Long As the SUM Long
Dim As Long, I t As Long

SUM=32: ReDim aBuf (SUM)
For I=0 To SUM
ABuf (I)=I + 1
Next
Randomize: sOut=""
For I=1 To 6 'red ball
T=SUM * Rnd
SOut=sOut & amp; Right $(" 0 "& amp; ABuf (t), 2) & amp; "
"ABuf (t)=aBuf (SUM)
SUM=SUM - 1
Next
SOut=sOut & amp; Right $(" 0 "& amp; CInt 15 * (1 + 0.98), 2)
MsgBox sOut
End Sub

CodePudding user response:

Dizzy, CInt 15 * (1 + 0.98) this 0.98 forgot to Rnd,

CodePudding user response:

refer to the second floor Chen8013 response:
you said "no coincidence" refers to the random generation of a note no repeat number is the number?
To save to Excel, the said too vague...
Is the documents? Or create new document after a set number?
Every time how much of an note number? Is fixed, or a range of random? Before their input number or produce?

Alas, still see a note of the number of the first:
 Private Sub Command1_Click () 
Dim sOut As String
Dim aBuf (), As Long As the SUM Long
Dim As Long, I t As Long

SUM=32: ReDim aBuf (SUM)
For I=0 To SUM
ABuf (I)=I + 1
Next
Randomize: sOut=""
For I=1 To 6 'red ball
T=SUM * Rnd
SOut=sOut & amp; Right $(" 0 "& amp; ABuf (t), 2) & amp; "
"ABuf (t)=aBuf (SUM)
SUM=SUM - 1
Next
SOut=sOut & amp; Right $(" 0 "& amp; CInt 15 * (1 + 0.98), 2)
MsgBox sOut
End Sub


Is to want to have a program can be all the permutation and combination can be generated into a table, or the inside of the text,
  •  Tags:  
  • VBA
  • Related