Option Explicit
Private Sub Command1_Click()
Dim a(10) As Long, aMax As Long, i As Long, j As Long, k As Long
Dim s As String, t As Long
s = Text1.Text
For i = 1 To Len(s)
a(i - 1) = Mid$(s, i, 1)
aMax = i - 1
Next i
For i = 0 To aMax - 1
j = i + 1
t = a(j)
Do Until j < 1
If a(j - 1) > t Then
a(j) = a(j - 1)
j = j - 1
Else
Exit Do
End If
Loop
a(j) = t
Next i
s = ""
For i = 0 To aMax
For j = 0 To aMax
For k = 0 To aMax
If a(i) > 0 And i <> j And i <> k And j <> k Then s = s & a(i) & a(j) & a(k) & " "
Next k
Next j
Next i
Text2.Text = s
End Sub
这其实是有条件的全排列,
给你个大意的程序参考
假定数长为7,数据放在数组a中,a(1)=1,a(2)=2...
for i=1 to 5
for j=i+1 to 6
for k=j+1 to 7
? a(i);a(j); a (k); " ";
next k
next j
next i
zgwxm 正解..
Private Sub Command1_Click()
zf = Text1.Text
sz = Len(zf)
dzfc = ""
For i = 1 To sz - 1'是-1不是-2,不然得不到457
For j = i + 1 To sz - 1
For k = j + 1 To sz
dzfc = dzfc & " " & Trim(i) & Trim(j) & Trim(k)
Next k
Next j
Next i
Text1.Text = dzfc
End Sub
输入1234567
得到:123 124 125 126 134 135 136 145 146 156 234 235 236 245 246 256 345 346 356 456 457
Private Sub Command1_Click()
zf = Text1.Text
sz = Len(zf)
dzfc = ""
For i = 1 To sz - 2
For j = i + 1 To sz - 1
For k = j + 1 To sz
dzfc = dzfc & " " & Trim(i) & Trim(j) & Trim(k)
Next k
Next j
Next i
Text1.Text = dzfc
End Sub