Base 10 to Base 36 Conversion フォローする

John Harris

I'm trying to convert a numeric value to Base 36. Here's what I was able to find with some googling but Bartend (2019 R2) doesn't seem to like it much.

Sub main()
'Dim Value As Double
'base10Number = Int(Rnd * 1000)
Debug.Print Value, ConvertBase10(base10Number, "0123456789ABCDEFGHIJKLMPQRSTUVWXYZ")
End Sub

Public Function ConvertBase10(ByVal d As Double, ByVal sNewBaseDigits As String) As String
Dim S As String, tmp As Double, i As Integer, lastI As Integer
Dim BaseSize As Integer
BaseSize = Len(sNewBaseDigits)
Do While Val(d) <> 0
tmp = d
i = 0
Do While tmp >= BaseSize
i = i + 1
tmp = tmp / BaseSize
Loop
If i <> lastI - 1 And lastI <> 0 Then S = S & String(lastI - i - 1, Left(sNewBaseDigits, 1)) 'get the zero digits inside the number
tmp = Int(tmp) 'truncate decimals
S = S + Mid(sNewBaseDigits, tmp + 1, 1)
d = d - tmp * (BaseSize ^ i)
lastI = i
Loop
S = S & String(i, Left(sNewBaseDigits, 1)) 'get the zero digits at the end of the number
ConvertBase10 = S
End Function

it says there's a problem with the Sub syntax any ideas?

サインインしてコメントを残してください。