how do I convert a octal value to a regual number?
I can do it the other way around but not that way. HELP!
Printable View
how do I convert a octal value to a regual number?
I can do it the other way around but not that way. HELP!
what is a regual number?
I think you mean decimal value
example:Code:Function Base2Dec(val$, base%): Dim n%, a() As Byte
a = StrConv(UCase(val), vbFromUnicode)
For n = 1 To Len(val)
Base2Dec = CDec(Base2Dec + (a(n - 1) - 48 + 7 * (a(n - 1) > 64)) * base ^ (Len(val) - n))
Next n
End Function
Function Dec2Base$(val, base%): Dim n%, s
For n = 0 To 100
s = Int(val / base ^ n)
If s = 0 Then Exit For
s = s - Int(s / base) * base 's mod base
Dec2Base = Chr(s + 48 - 7 * (s > 9)) & Dec2Base
Next n
End Function
Msgbox Base2Dec(1000,8)
Take in your octal number as a string, for example:
Append the string "&O" (that's the letter "O" there) to the octal number string and use that as the argument to the Val function, assigning the result of that function to an Integer (or Long):Code:strOctNum = InputBox("Enter an octal number:")
Code:intDecimalNumber = Val("&O" & strOctNum)
Msgbox "The decimal equivalent is: " & intDecimalNumber