Re: The mystery of the missing (compound) variables.
- From: "Gordon Snider" <no-spam@xxxxxxxxxxxx>
- Date: Sat, 17 May 2008 14:29:19 +0200 (CEST)
On Sat, 10 May 2008 21:34:01 UTC, Pit Zyclade <pit@xxxxxxxx> wrote:
Gordon Snider schrieb:
On Wed, 7 May 2008 11:54:29 UTC, Pit Zyclade <pit@xxxxxxxx> wrote:....
phillips_js@xxxxxxxxxxx schrieb:
...
So I use a text file with a max 50 records as a number all alone on
its line (so I can recover it as a number) and a following space-
separated text string line which can be PARSEd. Code snippet:
IF STREAM(file,"C","QUERY EXISTS")\="" THEN DO
CALL STREAM file,"C","OPEN READ"
rec_num = 0
DO FILELN = 1 TO 50
IF STREAM(file,"S")\="READY" THEN
LEAVE
ln = LINEIN(file)
IF LEFT(ln,1) > 0 THEN DO
....
....
The DO instruction opens a loop that initializes the control variable....
FILELN to 1 and sets a
limit of 50 passes through the loop. This will stop reading files
greater
than 50 records, leaving the file OPEN and READY, and will pass
control
to the second last END clause.
The next IF instruction tests the STATE of the open file to see if it
is not equal
to 'READY'. The most likely reason for the STATE being not equal to
READY is
a NOTREADY condition due to END-OF-FILE. In the event of a STATE
other than READY the THEN LEAVE clause passes control to the second
last
END clause and the file is CLOSED with the CALL STREAM.
This clause would catch any files that had fewer than 50 records.
It would not catch any files that had exactly 50 or more records
because the control
variable of the DO loop (FILELN) would end looping after the 50th pass
and
send control to the second last END clause. The IF STREAM instruction
test for 'READY' would not be executed.
....
....
What happens by STRAEM(file,S)\=READY ???
This comparison is tested on each pass through the loop.
I fthere are fewer than 50 records in the file then the THEN LEAVE
is excuted to end the loop
I have tested in in my environment (WinXP, Rexx r4 from
KilowattSoftware) with a datfile test.txt structure:
line 1: several numbers separated with a blank
line 2: only one number
line 3: text without -delimiters
line 4: pure blank
line 5: text with - as a string
line 6: only one digit.
My test program:
file="test.txt"
IF STREAM(file,"C","QUERY EXISTS")\="" THEN DO
CALL STREAM file, 'C' , "open read"
SAY "file "file" is open yet"
END
DO ln = 1 TO 50
SAY ln
a = LINEIN(file)
SAY a
rc=STREAM(file,"S")
SAY rc
END
The result demonstrates a correct listing of the lines 1 to 6,
then following by blank lines and
50 READYs !
I doubt you got exactly 50. I got NOTREADY after line 7 up to ln =
50
Therefore, IF LINES(file)>0 or/and IF DATATYPE(left(a,1)\=N are better
statements for differentiation as STREAM(file,S).
I agree that LINES() is the better function to use when reading a
file.
Pit
Greifswald,Germany
--
Gordon Snider
Toronto, Canada
.
- Follow-Ups:
- Re: The mystery of the missing (compound) variables.
- From: Pit Zyclade
- Re: The mystery of the missing (compound) variables.
- References:
- The mystery of the missing (compound) variables.
- From: phillips_js
- Re: The mystery of the missing (compound) variables.
- From: Pit Zyclade
- Re: The mystery of the missing (compound) variables.
- From: Gordon Snider
- Re: The mystery of the missing (compound) variables.
- From: Pit Zyclade
- The mystery of the missing (compound) variables.
- Prev by Date: Re: How to write out a variable length record?
- Next by Date: Re: The mystery of the missing (compound) variables.
- Previous by thread: Re: The mystery of the missing (compound) variables.
- Next by thread: Re: The mystery of the missing (compound) variables.
- Index(es):
Relevant Pages
|