Chapter
10
I
BASIC
Ke-ywords
VAL
Function
VAL(string)
Calculates the numerical value
of
string.
VAL
is the inverse
of
the STR$ function; it returns the number
represented by the characters in
a
string argument. This num-
ber may be integer, single precision,
or
double precision, depend-
ing on the range
of
values and the rules used
for
typing all
constants
.
VAL
terminates its evaluation on the first character that has no
meaning in a numeric value.
If
the string is nonnumeric
or
null,
VAL
returns a zero.
Ex
ample
s
PRINT VAL("1 00 DOLLARS")
prints
100.
PRINT VAL("1234E5")
prints
123400000.
Sample Programs
10 READ NAME$, CITY$, STATE$, ZIP$
20 IF VALCZIP$)
<
90000
OR
VAL(ZIP$)
>
96699
THEN PRINT NAME$ TABC25) "OUT OF STATE"
30 IF VAL(ZIP$)
>
90801 AND VAL<ZIP$)
<=
90815
THEN PRINT NAME$ TAB(25) "LONG BEACH"
This program searches
for
zip codes within the specified ranges
to
determine if they are within Long Beach
or
"out
of
state.''
334