|&O10||=||Octal 10 (=decimal 8)|
|&H10||=||Hexadecimal 10 (=decimal 16)|
The VBA Oct function converts a supplied number into octal notation and returns the result as a string.
The syntax of the function is:
Note that, if the supplied Number is a decimal, it is rounded to the nearest integer before being converted to octal.
' Convert three different decimals into octal notation.
Dim oct1 As Stringoct3 = Oct( 1000 )
Dim oct2 As String
Dim oct3 As String
' oct3 is now equal to the String "1750".
After running the above vba code the variables oct1, oct2 and oct3 are equal to the Strings "10", "12" and "1750" respectively.
The VBA Oct function can also be used to convert hexadecimal values to octal notation, if the hexadecimal is preceded by &H.
' Convert the hexadecimal 3E8 into octal notation.Dim oct1 As String
oct1 = Oct( &H3E8 )
' oct1 is now equal to the String "1750".
Warning: Text representations of octals or hexadecimals (as returned by the Oct and Hex functions) are not recognised as octals or hexadecimals when supplied to VBA functions.
If the Oct function is supplied with a text string that cannot be interpreted as a numeric value, it will return the error: