代碼如下,所有的排列組合生成在妳D盤下的“字符組合.txt”內。
**********************************************************************
Option Explicit
Private Sub Command1_Click()
Dim Num, I, J, Temp, Len1 As Long
Dim FF As Long
Dim Count As Long
Dim str, strTemp, strArr, Arr() As String
'********************************************************************
str = InputBox("請輸入字符串,數字或者字母組成:", "By CoKie")
Len1 = Len(str): ReDim strArr(Len1)
For I = 1 To Len1
strArr(I - 1) = Mid(str, I, 1)
Next
'********************************************************************
Count = 1
For I = 2 To Len1
Count = Count * I
Next
ReDim Arr(Count)
'*********************************************************************
Randomize
For I = 0 To Count - 1
'******************************************
Lab2: strTemp = "": Num = 0
Do While Num < Len1
Lab1: Temp = Int(Rnd * Len1)
If InStr(strTemp, CStr(Temp)) Then GoTo Lab1
strTemp = strTemp & Temp
Num = Num + 1
Loop
'******************************************
For J = 0 To UBound(Arr)
If Arr(J) = strTemp Then GoTo Lab2
Next
Arr(I) = strTemp
Next
'**********************************************************************
FF = FreeFile
Open "D:\字符組合.txt" For Output As #FF
'**************************
For I = 0 To Count - 1
strTemp = ""
For J = 1 To Len1
strTemp = strTemp & strArr(CLng(Mid(Arr(I), J, 1)))
Next
Print #FF, strTemp
Next
'**************************
Close #FF
End Sub