Returns the numbers contained in a string as a numeric value of appropriate type.
Syntax
Val(string)
The required string argument is any valid string expression.
Remarks
The Val function stops reading the string at the first character it can't recognize as part of a number. Symbols and characters that are often considered parts of numeric values, such as dollar signs and commas, are not recognized. However, the function recognizes radix prefixes &O
(for octal) and &H
(for hexadecimal). Blanks, tabs, and linefeeds are stripped from the argument.
The following returns the value 168:
Val(" 16 8th Street N.")
In the example below, Val returns the decimal value -1 for the hexadecimal value shown:
Val("&HFFFF")
Note The Val function recognizes only the period (.) as a valid decimal separator. When a possibility exists that different decimal separators may be used (for example, in international applications), you should use CDbl instead to convert a string to a number.