Name
Val Function
Class
Microsoft.VisualBasic.Conversion
Syntax
Val(expression)-
expression Use: Required
Data Type: String or Char
Any string representation of a number
Return Value
A Double able to hold the number contained in
expression
Description
Converts a string representation of a number into a Double
Rules at a Glance
The
Valfunction starts reading the string with the leftmost character and stops at the first character that it does not recognize as being part of a valid number. For example, the statement:iNumber = Val("1A1")returns 1.
&Oand&H(the octal and hexadecimal prefixes) are recognized by theValfunction.Currency symbols, such as $ and £, and delimiters, such as commas, are not recognized as numbers by the
Valfunction.The
Valfunction only recognizes the period (.) as a decimal delimiter.Prior to processing
expression,Valremoves spaces, tabs, and line-feed characters.
Programming Tips and Gotchas
If you are developing an international application, you should use
the more modern, internationally aware CDbl
function to convert strings to numbers, since
CDbl can recognize all decimal separators.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access