By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

A97 OCT & HEX FN's - is there a similar DEC Fn or something to go to BASE10?

P: n/a
MLH
Seeking base 10 conversion for OCT
and HEX numbers. I see A97 as OCT & HEX
Fn's to convert decimal numbers to those
2 BASEs. What about the other way around?
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
MLH
FOUND IT.

CLng("&h" & [HexCode])
Nov 13 '05 #2

P: n/a
MLH, this one's easy.
Octal values are prepended with an ampersand (&), so 15 would be &17.
Hex values are prepended with an ampersand H, so 31 would be &H1F.

The Val function is smart enough to recognize the special prepended
characters.

intDecimalNumber = Val(&17)

if the Oct function was used, it returned a string, so to convert it
back you would use the syntax:

intDecimalNumber = Val("&" + strOctal)

for hex numbers the syntax would be:

intDecimalNumber = Val("&H" + strHex)

Cut and paste the following code for an example:

Private Sub ConvertOct()
Dim strOctal As String
Dim intDecimal As Integer
Dim intNewDecimal As Integer
intDecimal = InputBox("Enter any decimal value and press enter",
"GETTING A VALUE")
strOctal = Oct(intDecimal)
MsgBox "The octal value is " & strOctal
intNewDecimal = Val("&" + strOctal)
MsgBox "The octal value converted back to decimal is " &
str(intNewDecimal)
End Sub

Taking it one step further, you can write a function to accept an octal
and return a decimal:

Public Function OctalToDecimal(strOctal As String) As Integer
OctalToDecimal = Val("&" + strOctal)
End Function

Hope this helps.

Neil

Nov 13 '05 #3

P: n/a
MLH
Thanks for the very thorough reply and all your suggestions.
There certainly is more than one way to skin a cat.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

MLH, this one's easy.
Octal values are prepended with an ampersand (&), so 15 would be &17.
Hex values are prepended with an ampersand H, so 31 would be &H1F.

The Val function is smart enough to recognize the special prepended
characters.

intDecimalNumber = Val(&17)

if the Oct function was used, it returned a string, so to convert it
back you would use the syntax:

intDecimalNumber = Val("&" + strOctal)

for hex numbers the syntax would be:

intDecimalNumber = Val("&H" + strHex)

Cut and paste the following code for an example:

Private Sub ConvertOct()
Dim strOctal As String
Dim intDecimal As Integer
Dim intNewDecimal As Integer
intDecimal = InputBox("Enter any decimal value and press enter",
"GETTING A VALUE")
strOctal = Oct(intDecimal)
MsgBox "The octal value is " & strOctal
intNewDecimal = Val("&" + strOctal)
MsgBox "The octal value converted back to decimal is " &
str(intNewDecimal)
End Sub

Taking it one step further, you can write a function to accept an octal
and return a decimal:

Public Function OctalToDecimal(strOctal As String) As Integer
OctalToDecimal = Val("&" + strOctal)
End Function

Hope this helps.

Neil


Nov 13 '05 #4

P: n/a
Thanks from me as well. That's an excellent solution.

James A. Fortune

Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.