Val (function)

<< Click to Display Table of Contents >>

Val (function)

Val(String)

Converts a string to a number.

The string content is converted up to the first non-numeric character. Spaces, tabs and line feeds are ignored.

If the string does not start with a number, the result is 0.

Val ("2") gives 2

Val ("2 hours") gives 2

Val ("2 hours 30 minutes") gives 2

Val ("xyz 2") gives 0

See also: Str

Example:

Sub Main

 Dim Msg

 Dim YourVal As Double

 YourVal = Val(InputBox$("Enter a number."))

 Msg = "You entered the number " & YourVal

 MsgBox Msg

End Sub