HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)

4-: 117
---------------------------------------------------------------------------------------------
When reading from a binary file, HP Business BASIC/XL does not convert
data to the types of the variables to which it assigns them. For
example, if a program tries to read decimal data that is in a binary file
into real variables, the numbers returned are incorrect.
Examples
10 DATA 12,13,14
20 DATA 15,16,17,18
30 READ A,B !A=12, B=13
40 READ C !C=14
99 END
After line Data pointer is at: In line:
------------------------------------------------------------------------------------
--
20 12 10
30 14 10
40 15 20
If possible, a datum from a DATA statement is interpreted as the type of
data required by the variable into which it is read. If an underflow
occurs, the value zero is assigned to the variable. Before a datum is
assigned to a variable, it is converted to the type of the variable, if
possible. A numeric variable requires a numeric literal, and a string
variable requires a string literal or any unquoted string. Numeric
literals are also unquoted string literals and can thus be assigned to a
string variable.
10 DATA 1234, "56", "seven", "eight", 12
20 READ N,A$ !N=1234, A$="56"
30 READ B$, C$ !B$="seven", C$="eight"
40 READ D$ !D$="12"
99 END
Specification of a substring of a string variable does not always "use
up" the value that is read into it. However, following the READ, the
data pointer moves to the next datum anyway. The rules of substring
assignment apply to READ.
10 DIM Str$[3], Str_array$(1:5)[6]
20 DATA Anteater, Bear, Cat, Dog
30 READ Str$[1:3] !Str$="Ant"
40 READ Str_array$(1)[1,2], Str_array$(2)[1;1] ! Str_array$(1)="Be",
99 END ! Str_array$(2)="C"
The READ statement assigns values from left to right when multiple
variables are specified. Thus, variable subscripts can be assigned just
prior to assignment to an array element. For example, in the statement
2450 READ X,Y,A(X,Y)
values are assigned to X and Y before the subscripts of the A array are
evaluated.
An example of using READ statements with data files:
100 READ #1; A,B,C
110 READ #2,5; D$,E
120 READ #3,7,4; F(),G$(*,*)
130 READ #4; N,M,(FOR I=1 TO 5, A(I,I), B$(I,I))