Function to36(a As Long)
n="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
Do
If a < 36 Then n = Mid(n, a + 1, 1) & n: Exit Do
m = a Mod 36
n = Mid(n, m + 1, 1) & n
If a = 36 Then n = 1 & n: Exit Do
a = (a - m) / 36
Loop
End Function
Public Function tothirtysix(a As Long) As String
n = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
tothirtysix = ""
Do
If a < 36 Then tothirtysix = Mid(n, a + 1, 1) & tothirtysix: Exit Do
m = a Mod 36
tothirtysix = Mid(n, m + 1, 1) & tothirtysix
If a = 36 Then tothirtysix = Mid(n, 2, 1) & tothirtysix: Exit Do
a = (a - m) / 36
Loop
Public Function DoT(iD As Single) '10进制转换换36进制
On Error GoTo Err_Zone
Dim iY As Single, iD1 As Single
Dim sh As String, sH1 As String
DoT = ""
Do
iD1 = iD
iD1 = Int(iD1 / 36)
iY = iD - iD1 * 36
sh = DOTS(iY)
If iD1 < 36 Then
sH1 = DOTS(iD1)
DoT = sH1 & sh & DoT
Exit Do
End If
DoT = sh & DoT
iD = iD1
Loop
Exit Function
Err_Zone:
MsgBox "数据无效!"
End Function
Private Function DOTS(iDD As Single)
Select Case iDD
Case 0 To 9
DOTS = iDD
Case 10
DOTS = "A"
Case 11
DOTS = "B"
Case 12
DOTS = "C"
Case 13
DOTS = "D"
Case 14
DOTS = "E"
Case 15
DOTS = "F"
Case 16
DOTS = "G"
Case 17
DOTS = "H"
Case 18
DOTS = "I"
Case 19
DOTS = "J"
Case 20
DOTS = "K"
Case 21
DOTS = "L"
Case 22
DOTS = "M"
Case 23
DOTS = "N"
Case 24
DOTS = "O"
Case 25
DOTS = "P"
Case 26
DOTS = "Q"
Case 27
DOTS = "R"
Case 28
DOTS = "S"
Case 29
DOTS = "T"
Case 30
DOTS = "U"
Case 31
DOTS = "V"
Case 32
DOTS = "W"
Case 33
DOTS = "X"
Case 34
DOTS = "Y"
Case 35
DOTS = "Z"
Case Else
End Select
End Function
Function toNum(x, iStr$) '10进制转N进制,x为待转换数值,iStr为进制文本ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,有多少位就转成多少进制
Dim n, Res, Arr(), i
n = Len(iStr)
ReDim Arr(n)
For i = 1 To n
Arr(i - 1) = Mid(iStr, i, 1)
Next
Res = ""
Do While x >= n
num = x Mod n
x = (x - num) / n
Res = Arr(num) & Res
Loop
toNum = Arr(x) & Res
End Function
Public Function DoT(iD ...[/indent]
to_10 有bug 用0-5的数随机转换几次就出来bug了
[mw_shl_code=vb,true]Function to_36(a1 As Long, i)
nn = Application.Rept(0, 99)
n = "AB0123456789CDEFGHIJKLMNOPQRSTUVWXYZ"
a = a1
t = ""
If a < 36 Then
t = Mid(n, a + 1, 1)
If Len(t) < i Then
to_36 = Right(nn & t, i)
End If
Exit Function
End If
xx:
m = a Mod 36
t = Mid(n, m + 1, 1) & t
s = Int((a - m) / 36)
If s >= 36 Then
a = s
GoTo xx
Else
t = Mid(n, s + 1, 1) & t
End If
If Len(t) < i Then
to_36 = Right(nn & t, i)
Else
to_36 = t
End If
End Function
'这部分有bug 不知道那里有问题
Function to_10(a1 As String)
n = "AB0123456789CDEFGHIJKLMNOPQRSTUVWXYZ"
a = a1
i = Len(a)
s = 0
For x = 1 To i
If Mid(a, x, 1) <> 0 Then
a = Mid(a, x, 99)
Exit For
End If
Next
i = Len(a)
ReDim ar(1 To i)
For x = 1 To i
b = InStr(n, Mid(a, x, 1)) - 1
ar(x) = b
Next
If i = 1 Then
to_10 = ar(1)
ElseIf i = 2 Then
to_10 = ar(1) * 36 + ar(2)
ElseIf i = 3 Then
to_10 = ar(1) * 36 ^ 2 + ar(2) * 36 + ar(3)
ElseIf i = 4 Then
to_10 = ar(1) * 36 ^ 3 + ar(2) * 36 ^ 2 + ar(3) * 36 + ar(4)
ElseIf i = 5 Then
to_10 = ar(1) * 36 ^ 4 + ar(2) * 36 ^ 3 + ar(3) * 36 ^ 2 + ar(4) * 36 + ar(5)
ElseIf i = 6 Then
to_10 = ar(1) * 36 ^ 5 + ar(2) * 36 ^ 4 + ar(3) * 36 ^ 3 + ar(4) * 36 ^ 2 + ar(5) * 36 + ar(6)
End If
End Function