CitectVBA Programming Reference > CitectVBA Function Reference > Conversion Functions > Val

Val

Converts a text string containing numeric characters to a numeric value. The Val function expects the argument Str to be a valid string expression. The Val function stops reading the string when it reaches a non numeric character.

Symbols such as dollar signs and commas are not recognised; however, radix prefixes for octal (&0) and hexadecimal (&H) are. Blanks, tabs and linefeeds are stripped out from the return.

The Val function performs the opposite of the Str function, which converts a numeric value to a text string containing numeric characters.

Syntax

Val(Str)

Str:

A string or expression that can represent a valid text value.

Return Value

Returns the numeric value of a string of characters extracted from the Str provided in the argument.

Related Functions

Format | Hex | Oct | Str

Example

Dim vntVar		 ' declare result holder variable
vntVar = Val("65") ' returns 65
vntVar = Val("90 Main St.") ' returns 90
vntVar = Val("12+34+56") ' returns 12
vntVar = Val(" 12 34 56 ") ' returns 123456
vntVar = Val("&0FF") ' returns
vntVar = Val("Zoe") ' returns 0