Val Procedure

Returns the numerical value of a string sStr based on the predefined radix lBase.

Syntax

[ d = ] Val ( sStr [, lBase ] )

The Val procedure syntax has the following parts:

Name

Type

Description

d

Double

The converted number

sStr

Val BString

String to convert

lBase

Val Long

Radix to use in conversion (2-36 or 0). The default value is 0.

Comments

Val may be used to convert strings to numbers in various radixes.

If lBase is 10, the string can have the following format:

[whitespace] [sign] [digits] [.digits] [ e | E][sign]digits]

Where whitespace consists of a space or tab character.

The first character that does not fit this format stops the conversion.

If lBase is not 10, the string can have the format:

[whitespace] [+ | -] [0 [ x | X ]] [digits]

If lBase is between 2 and 36, then it is used as the base of the number.

If lBase is 0, the initial characters of the string are used to determine the base.

The function returns 0 if no conversion could be performed.

Example

d = Val("123.456ABc",10) ! now d = 123.456

d = Val("FF", 16) ! now d = 255

d = Val("0xFF") ! now d = 255

d = Val("0b101") ! now d = 5

d = Val("010", 0) ! now d = 8

d = Val("77", 8) ! now d = 63

d = Val("101", 2) ! now d = 5

dl= Val("-9223372036854775808") ! now dl(DLong)=-9223372036854775808

See Also

Chr, Format, Str