這幾天把遞迴練得比較熟悉了。 Dim a(10), x As String Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do While Not EOF(1) List1.Clear Line Input #1, x For i = 1 To 10 a(i) = Mid(x, i, 1) Next Call abc("") For i = 0 To (List1.ListCount - 1) Print #2, List1.List(i) Next Print #2, i Loop Close Close End End Sub Sub abc(t) If Len(t) = Len(x) Then List1.AddItem t Else For i = 1 To Len(x) If InStr(t, a(i)) = 0 Then Call abc(t & a(i)) Next End If End Sub
這幾天把遞迴練得比較熟悉了。
回覆刪除Dim a(10), x As String
Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do While Not EOF(1)
List1.Clear
Line Input #1, x
For i = 1 To 10
a(i) = Mid(x, i, 1)
Next
Call abc("")
For i = 0 To (List1.ListCount - 1)
Print #2, List1.List(i)
Next
Print #2, i
Loop
Close
Close
End
End Sub
Sub abc(t)
If Len(t) = Len(x) Then
List1.AddItem t
Else
For i = 1 To Len(x)
If InStr(t, a(i)) = 0 Then Call abc(t & a(i))
Next
End If
End Sub