|
A1=120,则B1=N2chrx(A1)
- Function N2ChrX(ByVal L As Long) As String
- '作用:将Long值转换为 N 进制所表示的字符串
- Dim iMod As Integer, dInt As Double, sChar As String
- Dim ws%, fws%, zxx%, i%, j%, nf$, bb$, a$, a1$, a2$, b, wc, w%, j1
- Const Jzs As String = "0123456789BCDFGHJKLMNPQRSTVWXYZ"
- Const zd& = 2147483647
- Const zx& = -2147483648#
- Const N = 31
- If L = 0 Then N2ChrX = L: Exit Function
- If L > 0 Then
- iMod = L Mod N
- dInt = Int(L / N)
- If iMod > 0 Then
- sChar = Mid$(Jzs, iMod + 1, 1)
- ElseIf dInt > 0 Then
- sChar = "0"
- End If
- Do While dInt > 0
- iMod = dInt Mod N
- dInt = Int(dInt / N)
- If iMod > 0 Then
- sChar = Mid$(Jzs, iMod + 1, 1) & sChar
- ElseIf dInt > 0 Then
- sChar = "0" & sChar
- End If
- Loop
- Else
- nf = N2ChrX(zd)
- ws = Len(nf)
- If L = zx Then
- L = zd
- zxx = 1
- GoTo 100
- Else
- L = -L
- End If
- nf = N2ChrX(L)
- fws = Len(nf)
- wc = ws - fws
- If wc > 0 Then
- nf = Application.Rept("0", wc) & nf
- End If
- 100:
- For i = 1 To ws '负码=反码+1
- bb = Mid$(nf, i, 1)
- w = InStr(Jzs, bb)
- If i = 1 Then
- sChar = Mid$(Jzs, N - w + 1, 1)
- ElseIf i <> ws Then
- sChar = sChar & Mid$(Jzs, N - w + 1, 1)
- Else
- If zxx = 0 Then
- sChar = sChar & Mid$(Jzs, N - w + 1, 1) '最后一位+1
- For j = ws To 1 Step -1
- cc = Mid$(sChar, j, 1)
- cc = InStr(Jzs, cc) - 1
- j1 = cc + 1
- If j1 = N Then
- sc = "0" & sc
- Else
- j1 = Mid$(Jzs, j1 + 1, 1)
- sc = j1 & sc
- sChar = Left$(sChar, j - 1) & sc
- Exit For
- End If
- Next j
- Else
- sChar = sChar & Mid$(Jzs, N - w + 1, 1)
- End If
- End If
- Next i
- End If
- 200:
- N2ChrX = sChar
- End Function
复制代码 |
|