Re: The mystery of the missing (compound) variables.



On May 10, 5:34 pm, Pit Zyclade <p...@xxxxxxxx> wrote:
Gordon Snider schrieb:



On Wed, 7 May 2008 11:54:29 UTC, Pit Zyclade <p...@xxxxxxxx> wrote:

phillips...@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” ???
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 “READY”s !
Therefore, IF LINES(file)>0 or/and IF DATATYPE(left(a,1)\=”N” are better
statements for differentiation as STREAM(file,”S”).

Pit
Greifswald,Germany- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Well, it seems I should have been much more EXPLICIT in describing the
mystery !

/* REXX - Code to read file */

file = 'mydata.dat'

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
rec_num = rec_num + 1
array1.rec_num = ln
SAY "Rec Num "rec_num array1.rec_num
END
ELSE DO
PARSE VALUE ln WITH " "array2.rec_num" "array3.rec_num"
"array4.rec_num
/* displays records correctly */
SAY array2.rec_num array3.rec_num array4.rec_num
END
END

CALL STREAM file, "C", "CLOSE"
END

/* following line displays all records correctly EXCEPT for */
/* the LAST record */
SAY array2.rec_num array3.rec_num array4.rec_num

/********** End of Code ************/

As I stated the 'mydata.dat' file is "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." A 3-record text file is shown below:

23
<SP>array2.1<SP>array3.1<SP>array4.1
12
<SP>array2.2<SP>array3.2<SP>array4.2
57
<SP>array2.3<SP>array3.3<SP>array4.3

So I used the space delimiters <SP> to make sure LEFT(ln,1) and the
PARSE template would truely differentiate the lines in the file. It
turned out that LEFT(ln,1) > 0 didn't do a good job and
DATATYPE(LEFT(ln,1)) == "NUM" would have been much more robust.

Regardless, this didn't solve the mystery.

It seems that what I thought was the end of file was not, and the
exit:

IF STREAM(file,"S")\="READY" THEN
LEAVE

wasn't being triggered before the test LEFT(ln,1) > 0 failed, and some
end-of-file fragment was PARSEd to result in null array2.rec_num,
array3.rec_num, array4.rec_num members.

Anyway I fooled around with it, ensuring the file was truely truncated
at the last record etc., and found that replacing the PARSE line with

PARSE VALUE LINEIN(file) WITH " "array2.rec_num" "array3.rec_num"
"array4.rec_num

solved the problem.

Pit, Gordon, I really don't know why the mystery exists and I can only
guess why the substitute PARSE statement works. It may be a bug in the
Enterprise Alternatives flavor of REXX, who knows ?
"End Of Line"
.



Relevant Pages

  • Re: How to OpenRecordset(queryName refering to form)
    ... Yes, you can store the where clause in the table field, but when it's read in the code it will indeed be treated a string - stupid of me. ... It is still possible to do it in a similar fashion, though more complicated: you would need a separate table with a one to many relationship to the forms, one record per field to filter on with fields for FormName, FieldName, FormCOntrolName and type; then you would need to open this table as a recordset in your code, filtering on the form name, and loop through the records constructing the Where clause. ... Alternatively, you could use a convention like: no additional table, all the info for fields to filter on comes from the form itself: for all fields you wish to filter on, name the corresponding control on the form with a perfix followed by the field name, then loop in your code through the form controls and add to the where clause string for those controls starting fltr, extracting the field name from the control name -4)...). ...
    (microsoft.public.access.queries)
  • Re: The mystery of the missing (compound) variables.
    ... separated text string line which can be PARSEd. ... limit of 50 passes through the loop. ... to the second last END clause. ... other than READY the THEN LEAVE clause passes control to the second ...
    (comp.lang.rexx)
  • Re: Multiselect listbox parameter query followup
    ... The easier way would be to create the WHOLE query as a string, ... SELECT up to the WHERE clause your code produces. ... code produces to a control on my form. ...
    (microsoft.public.access.queries)
  • Re: The mystery of the missing (compound) variables.
    ... Here is how I see this snippet. ... The THEN clause consists of a DO clause whose END is the ... The DO instruction opens a loop that initializes the control variable ...
    (comp.lang.rexx)
  • Re: OpenForm with Where Clause
    ... So how would I do a pattern match on a field that had data like DMH10257 or ... Dim strWhere As String ... of unbound search controls on different types of fields, ... about the Like condition in the where clause? ...
    (comp.databases.ms-access)