Home > Language Reference > String Management Functions > Val

Val

The Val function converts the specified string into a number.

Usage

Used to concatenate an integer to a string. The integer must be first converted to a string before the concatenation (the concatenation operator is the + sign).

Syntax

number=Val(<source_string>)

Parameter

<source_string>, string representing a numeric.  

Return value

number, integer, result of the conversion. If <string> does not begin with a numeric character, the return value is 0.

Remarks

The Val function will stop reading the string once it encounters the first non-numeric character. This does not include spaces.

See also

Asc
Chr$
Encrypt
ExtractBetween$
InStr
InStrRev
LCase$
Left$
Len
LTrim$
Mid$
Replace$
Right$
RTrim$
SplitIntoArray
Str$
Trim$
UCase$

Examples

number = Val("123") ' Returns the integer 123

number = Val("-123") ' Returns the integer -123

number = Val("12X3") ' Returns the integer 12

number = Val(var$)

Dim array$(10)
ReadExcel("c:\wttest\quotation.xlsx","A10:A10",array$())
number=Val(array$(0)) 'ReadExcel returns a string in array$(0) 
' which is the content of A10 cell, Val function converts to a number