Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - Base 34 Conversion


Group,
Can someone show me how I can use VBA to make a Base 34
conversion?

Tony


--
ajocius
------------------------------------------------------------------------
ajocius's Profile: http://www.excelforum.com/member.php...o&userid=17695
View this thread: http://www.excelforum.com/showthread...hreadid=401691

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default VBA - Base 34 Conversion

I needed some big base routines a few years ago and came up with these.
While I'm sure real math heads could do it more efficiently, fwiw:

Dim CharArray() As String

Sub Test()
''Converts 30 to base 34
MsgBox Base10ToX(30, 34)
End Sub

Sub TestBackToTen()
''Converts U (base 34) to base 10
MsgBox BaseXTo10("U", 34)
End Sub

'Supports bases up to 36
Function Base10ToX(Number As Long, NewBase As Integer) As String
Dim Balance As Long, Remainder As Long
If MakeCharArray(NewBase) Then
Balance = Abs(Number)
Do
Remainder = Balance Mod NewBase
Base10ToX = CharArray(Remainder) & Base10ToX
Balance = (Balance - Remainder) / NewBase
Loop While Balance 0
If Number < 0 Then Base10ToX = "-" & Base10ToX
Else
Base10ToX = "error"
End If
End Function

Function BaseXTo10(NumStr As String, NewBase As Integer) As Long
Dim Counter As Integer, IsNeg As Boolean
Dim CurrChar As String, NumStrLen As Integer
Dim CurrDigitValue As Integer, ResultNum As Double
If MakeCharArray(NewBase) Then
If Left(NumStr, 1) = "-" Then
NumStr = Trim(Mid(NumStr, 2, 99))
IsNeg = True
End If
NumStrLen = Len(NumStr)
For Counter = 1 To NumStrLen
CurrChar = Mid(NumStr, NumStrLen - Counter + 1, 1)
CurrDigitValue = Application.Match(CurrChar, CharArray, 0) - 1
ResultNum = ResultNum + CurrDigitValue * NewBase ^ (Counter - 1)
Next
If IsNeg Then ResultNum = -ResultNum
BaseXTo10 = ResultNum
Else
BaseXTo10 = 0
End If
End Function

Function MakeCharArray(Base As Integer) As Boolean
Dim Counter As Integer, TempInt As Integer
If Base 1 And Base < 37 Then
ReDim CharArray(0 To Base - 1)
For Counter = 0 To Base - 1
TempInt = Counter + 48
If TempInt 57 Then TempInt = TempInt + 7
CharArray(Counter) = Chr(TempInt)
Next
MakeCharArray = True
End If
End Function

--
Jim
"ajocius" wrote in
message ...

Group,
Can someone show me how I can use VBA to make a Base 34
conversion?

Tony


--
ajocius
------------------------------------------------------------------------
ajocius's Profile:
http://www.excelforum.com/member.php...o&userid=17695
View this thread: http://www.excelforum.com/showthread...hreadid=401691



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default VBA - Base 34 Conversion

Search the google.com archives of the XL newsgroups. You will find any
number of solutions including this one:
http://groups.google.com/group/micro...c/browse_frm/t
hread/5923bd418ffe3207/b3cd2d0f7f2bb5e5

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...

Group,
Can someone show me how I can use VBA to make a Base 34
conversion?

Tony


--
ajocius
------------------------------------------------------------------------
ajocius's Profile:
http://www.excelforum.com/member.php...o&userid=17695
View this thread: http://www.excelforum.com/showthread...hreadid=401691


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Base 60 input Howard Excel Discussion (Misc queries) 8 January 17th 10 12:46 AM
data base puiuluipui Excel Discussion (Misc queries) 4 November 2nd 06 12:26 PM
sum of top 5 base on one condition luvgreen Excel Worksheet Functions 3 June 28th 06 05:51 AM
Change base 6 to base 10? Brian Clarke Excel Discussion (Misc queries) 4 May 9th 06 02:24 PM
Change the base John Wright Excel Discussion (Misc queries) 3 May 16th 05 04:28 PM


All times are GMT +1. The time now is 05:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"