Option Explicit Private Sub Command1_Click() Dim Num, I, J, Temp, Len1 As Long Dim FileNO As Long Dim Count As Long Dim str, strTemp, strArr() As String, Arr() As String '******************************************************************** str = InputBox("请输入字符串,数字或者字母组成:", "提示") If str = "" Then Exit Sub '===by gary20130208 'Len1 = Len(str): ReDim strArr(Len1) strArr() = Split(str, " ") Len1 = UBound(strArr) + 1 ' 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 '********************************************************************** FileNO = FreeFile Open "e:\字符组合.txt" For Output As #FileNO '************************** For I = 0 To Count - 1 strTemp = "" For J = 1 To Len1 strTemp = strTemp & strArr(CLng(Mid(Arr(I), J, 1))) & "," Next Print #FileNO, Left(strTemp, Len(strTemp) - 1) Next '************************** Close #FileNO End Sub
这是网上找到的一段代码(vb 6.0版本),原来是算单个字符有多少种组合。我在这基础上做了下修改。
比如:A B C D E ,这样就总共有120种组合字符,然后输出到文本文件。