View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
isabelle isabelle is offline
external usenet poster
 
Posts: 587
Default Convert numerals

thank Auric! for this very useful function
ps /
to prevent overtaking 2147483647, i added this line
If what 2147483647 Then toBase = 0: Exit Function
but if you have another solution, i'm interested

isabelle

Le 2013-03-09 02:02, Auric__ a écrit :

Homework, anyone?

Function toBase(ByVal what As Variant, base As Long) As String
'Should be able to handle any decimal number to the limits of a variant,
'and bases from 2 to 36.
If (base < 2) Or (base 36) Or (Int(what) < what) Then Exit Function
Dim tmp As String
Static digits As Variant
If IsEmpty(digits) Then digits = Array("0", "1", "2", "3", "4", "5", _
"6", "7", "8", "9", "A", "B", _
"C", "D", "E", "F", "G", "H", _
"I", "J", "K", "L", "M", "N", _
"O", "P", "Q", "R", "S", "T", _
"U", "V", "W", "X", "Y", "Z")
While (what < 0)
tmp = digits(what Mod base) & tmp
what = what \ base
Wend
toBase = tmp
End Function

For base 37+ add your extra digits to the end of the array and change 36 to
your new max.