1,065
社区成员




Option Explicit
Sub Carry(a() As Long, ByVal m As Long, ByVal n As Long)
Dim Idx As Long
Idx = n
While a(Idx) = m
Idx = Idx - 1
m = m - 1
Wend
a(Idx) = a(Idx) + 1
While Idx < n
Idx = Idx + 1
a(Idx) = a(Idx - 1) + 1
Wend
End Sub
Sub PrintCom(a() As Long, n As Long)
Dim i As Long
ReDim tmp(n)
For i = 1 To n
tmp(i) = a(i)
Next
Debug.Print Trim(Join(tmp))
End Sub
Private Sub Command1_Click()
Dim m As Long, n As Long
Dim i As Long
m = 9
n = 3
ReDim a(m) As Long
For i = 1 To m
a(i) = i
Next
a(0) = -1
Do
DoEvents
Call PrintCom(a, n)
Call Carry(a, m, n)
Loop Until a(0) = 0
End Sub
Option Explicit
Sub Carry(a() As Long, ByVal m As Long, ByVal n As Long)
Dim Idx As Long
Idx = n
While a(Idx) = m
Idx = Idx - 1
m = m - 1
Wend
a(Idx) = a(Idx) + 1
While Idx < n
Idx = Idx + 1
a(Idx) = a(Idx - 1) + 1
Wend
End Sub
Sub PrintCom(a() As Long, n As Long)
Dim i As Long
ReDim tmp(n)
For i = 1 To n
tmp(i) = a(i)
Next
Debug.Print Trim(Join(tmp))
End Sub
Private Sub Command1_Click()
Dim m As Long, n As Long
Dim i As Long
m = 9
n = 3
ReDim a(m) As Long
For i = 1 To m
a(i) = i
Next
Do
DoEvents
Call PrintCom(a, n)
Call Carry(a, m, n)
Loop Until a(0) = 1
End Sub