Private Sub Command1_Click()
Dim num(1 To 10) As Long
Dim i As Long
For i = 1 To 10
num(i) = i
Next
For i = 1 To 10
SumX CStr(num(i)), num(i), 11, i + 1, num
Next
End Sub
Private Sub SumX(strPre As String, nOp1 As Long, nSum As Long, nStart As Long, aArr() As Long)
Dim i As Long
For i = nStart To UBound(aArr)
If nOp1 + aArr(i) = nSum Then
Debug.Print strPre & "+" & CStr(aArr(i)) & "=" & CStr(nSum)
End If
SumX strPre & "+" & CStr(aArr(i)), nOp1 + aArr(i), nSum, i + 1, aArr()
Next
End Sub
Type Ntype
Num As Integer
Select As Boolean
End Type
Public N() As Ntype
Public Pointer As Integer
Public Function ShowSNum() As String '显示已选的数
Dim I As Integer, tmp As String
For I = 1 To Pointer
If N(I - 1).Select Then
tmp = tmp & Str(N(I - 1).Num) & " "
End If
Next I
ShowSNum = tmp
End Function
Public Function NSelect() As Integer '已选数的个数
Dim I As Integer, S As Integer
S = 0
For I = 1 To Pointer
If N(I - 1).Select Then
S = S + 1
End If
Next I
NSelect = S
End Function
Public Function ShowAll(P As Integer) As String '显示函数
Dim I As Integer
If NSelect = 10 Then
ShowAll = ShowSNum + Chr(13) + Chr(10)
Else
For I = P To Pointer '体现选择的单向性,因为是组合不是排列
N(I - 1).Select = True
Form1.Text1.SelText = ShowAll(I + 1) '用一个文本框保存结果
N(I - 1).Select = False
Next I
End If
End Function
Private Sub Command1_Click()
Dim I As Integer
Pointer = InputBox("想生成几个数据?", "Input Number")
ReDim N(Pointer - 1)
N(0).Num = Int(Rnd(1) * 10)
N(0).Select = False
Text1.SelText = Str(N(0).Num) & " "
For I = 1 To Pointer - 1
N(I).Num = N(I - 1).Num + Int(Rnd(1) * 5 + 1)
N(I).Select = False
Text1.SelText = Str(N(I).Num) & " "
Next I
Text1.SelText = Chr(13) & Chr(10)
End Sub