Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / November 2006

Tip: Looking for answers? Try searching our database.

How to get different base systems so letters will show up like hex system tia sal2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
temp@temp.com - 30 Nov 2006 08:33 GMT
Greetings all
I now to I can convert between different base systems using the code
Function baseconv(InputNum, BaseNum)
  Dim quotient, remainder As Single
  Dim answer As String

  quotient = InputNum   ' Set quotient to number to convert.
  remainder = InputNum  ' Set remainder to number to convert.
  answer = ""

  Do While quotient <> 0   ' Loop while quotient is not zero.

     ' Store the remainder of the quotient divided by base number in a
     ' variable called remainder.

     remainder = quotient Mod BaseNum

     ' Reset quotient variable to the integer value of the quotient
     ' divided by base number.

     quotient = Int(quotient / BaseNum)

     ' Reset answer to contain remainder and the previous answer.
     answer = remainder & answer
     ' Convert answer variable to a number.
  Loop
     baseconv = Val(answer)
End Function

but how can I get letters to show up in bases like 25 or 40?
Like in the Hex system.

Thanks
SAL2
Leo Heuser - 30 Nov 2006 09:21 GMT
> Greetings all
> I now to I can convert between different base systems using the code
[quoted text clipped - 30 lines]
> Thanks
> SAL2

Here's one way:

Function Conv(Figure As String, _
   FromBase As Long, _
   ToBase As Long, _
   Optional NumberOfDigits As Long) As String
'Leo Heuser, October 1999, September 2006
'=conv(Figure,FromBase,ToBase,NumberOfDigits)
'Examples: =conv(1234,6,16,6) or =conv("45ff",16,2,32)
'If NumberOfDigits is set to 0, left out or set to fewer digits
'than are in the result, the result will be displayed without
'leading zeroes.
'The setup will convert a number from base 2-16
'to another base 2-16, but the string Digits can be
'expanded to Z, and thereby covering base 2 through 36
'If the line "Figure = UCase(Figure)" is deleted, it's possible
'to place lower case letters in Digits to cover base 2-62.
'Please keep the above text, if you pass on this routine.

Dim Digits As String
Dim ToBaseTen As Currency
Dim Dummy As Variant
Dim Counter As Long
Dim Result As String
   Conv = "Input error"
   Digits = "0123456789ABCDEF"
   If ToBase > Len(Digits) Then Exit Function
   Figure = UCase(Figure)
   For Counter = 1 To Len(Figure)
       Dummy = Mid$(Figure, Counter, 1)
       If InStr(Left$(Digits, FromBase), Dummy) = 0 Then
           Exit Function
       Else
           ToBaseTen = ToBaseTen + (InStr(Digits, Dummy) - 1) * _
               (FromBase ^ (Len(Figure) - Counter))
       End If
   Next Counter
   While ToBaseTen > 0
       Result = Mid$(Digits, ToBaseTen - Int(ToBaseTen / ToBase) * _
           ToBase + 1, 1) & Result
       ToBaseTen = Int(ToBaseTen / ToBase)
   Wend
   If NumberOfDigits = 0 Or NumberOfDigits < Len(Result) Then
       Conv = Result
   Else
       Conv = Right$(String$(NumberOfDigits - Len(Result), "0") & _
           Result, NumberOfDigits)
   End If
End Function

Signature

Best regards
Leo Heuser

Followup to newsgroup only please.


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.