4.7.4 VAL function
Converts the contents of a string to a number. Additionally, start and end characters in the string
may be optionally specified. The conversion continues until the first non-numeric character is
encountered; if there are no numeric characters, the value is 0.
Syntax:
VAL <string>
VAL <string> <character count expression>
VAL <string> <start character expression> <character count expression>
Examples:
LET A = VAL “1234567”
Converts the string to a number and therefore assigns value 1234567 to variable A.
LET A = VAL “1234567” 4
Converts only the first 4 characters of the string to a number. The leftmost 4 characters are used,
because the start character has not been specified and 1 is assumed. The value 1234 is assigned
to variable A.
LET A = VAL “1234567” 5 2
Converts only 2 characters of the string to a number, starting at character number 5. The value 56
is assigned to variable A.
LET A = VAL “123HELLO”
Assigns value 123 to variable A, because the conversion continues until the first non-numeric
character is found (the H of HELLO).
LET A = VAL “HELLO123”
Assigns value 0 to variable A, because there are no numeric characters at the beginning (left) of
the string.
LET A = VAL “1234567” 4 + 1 1 + 2
Assigns value 567 to variable A. This is because the <start character expression> and <character
count expression> are both expressions. An expression can include variables, or other functions.
In this case, the start character is 4 + 1 (which is 5) and the character count is 1 + 2 (which is 3).
So 3 characters from the string are converted, starting at position 5.
Strings can contain #-tag substitutions:
LET H = VAL “#1.2TM”
LET H = VAL “#TM” 1 2
Both of these are different ways of doing the same thing. In the first one, the tag is replaced by the
first two characters of the #TM (time) – start character is 1 and character count is 2. In the second
example, the whole #TM string is used, but the VAL function has start character 1 and character
count 2 specified. So in both cases, the first two characters (the hour of the time) are converted to
a number and put in variable H.
U4B operating manual Rev 1.00
30