Function CreateString(YStr As String, Optional StrLen As Long = 6, Optional NumPD As Boolean = True, Optional UAPD As Boolean = True, Optional LAPD As Boolean = True, Optional TSFHPD As Boolean = False, Optional TSFH As String = "/*-+~!@#$%^&()_=\;:'"",.<>?") As String
Dim SLen As Long, I As Long
Dim S() As String, TAsc As Long
Dim TStr As String, JWPD As Boolean
Dim JgStr As String
Const NumMin As Long = 48
Const NumMax As Long = 57
Const UAMin As Long = 65
Const UAMax As Long = 90
Const LAMin As Long = 97
Const LAMax As Long = 122
TStr = ""
JgStr = ""
If UAPD Then TStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
If LAPD Then TStr = TStr & "abcdefghijklmnopqrstuvwxyz"
If NumPD Then TStr = TStr & "0123456789"
If TSFHPD Then TStr = TStr & TSFH
If YStr = "" Then
For I = 1 To StrLen
YStr = YStr & Left(TStr, 1)
Next
End If
SLen = Len(YStr)
ReDim S(SLen - 1)
For I = 1 To SLen
S(I - 1) = Mid(YStr, I, 1)
JgStr = JgStr & Right(TStr, 1)
Next
If Join(S, "") = JgStr Then CreateString = "": Exit Function
If S(UBound(S)) = Right(TStr, 1) Then
S(UBound(S)) = Left(TStr, 1)
For I = SLen - 1 To 1 Step -1
If JWPD Then S(I - 1) = Left(TStr, 1)
JWPD = False
If S(I - 1) = Right(TStr, 1) Then
S(I - 1) = Left(TStr, 1)
JWPD = True
Else
S(I - 1) = Mid(TStr, InStr(TStr, S(I - 1)) + 1, 1)
Exit For
End If
Next
Else
S(UBound(S)) = Mid(TStr, InStr(TStr, S(UBound(S))) + 1, 1)
End If
CreateString = Join(S, "")
End Function
|