Name

Val Function — Microsoft.VisualBasic.Conversion

Synopsis

Val(expression)
expression required; 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. The Val function 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.

&O and &H (the octal and hexadecimal prefixes) are recognized by the Val function and the period (.) is recognized as a decimal delimitor. Currency symbols, such as $ and £, and delimiters, such as commas, are not recognized. Prior to processing expression, Val removes spaces, tabs, and line-feed characters.

Get VB.NET Language Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.