Val

Expression = Val ( String )

Convert a string into a boolean, a number or a date, according to the string contents.

The current localization is used for converting numbers and dates. So beware that date, time, decimal and thousands separators change with the language!

The conversion algorithm is the following:

  • If the string can be interpreted as a date & time (with date or time separators), then the date & time is returned.

  • Else, if the string can be interpreted as a floating point number, then this floating point number is returned.

  • Else, if the string can be interpreted as a 64 bits long number, then this long number is returned.

  • Else, if the string can be interpreted as an integer number, then this integer number is returned.

  • Else, if the string is "True" or "False", then the matching boolean value is returned.

  • Otherwise, NULL is returned.

Val() can interpret dates generated by the gb.Standard date format.

Examples

PRINT Val("09/06/72 01:00")
09/06/72 01:00:00

PRINT Val("3.1415")
3.1415

PRINT Val("-25")
-25

Print Val("&H123abc")  ' &H indicates HEX number
1194684

PRINT Val("True")
True

PRINT IsNull(Val("Gambas"))
True

See also