How to read a file

jhdz

New Member
Hi I am new in progress also and I am have some problems trying to figure it out how to read a file with progress . What am trying to do is read the whole line of the file and put it into a temp table but the last line it is not read it because it does not have the new line (enter/skip) , so what I want to do is add that new line (enter or skip ) to that last line. Any Idea? Any help would be really appreciated. this is how it looks the code.

Define Temp-table LockBoxFile No-undo
Field Company as character format "x(50)":u label "Part"
Field LockboxNum as Character .

INPUT FROM Value(file).

REPEAT:
CREATE LockBoxFile.

Import UNFORMATTED LockboxNum .
END.
INPUT CLOSE.
For each LockboxFile:
If LockboxNum = "" Then
delete LockboxFile.
End.


define var i as integer.
output to "x:\test.txt".
For each LockboxFile:
message LockboxFile.LockboxNum .
i = i + 1.
End.
output close.
display i.
 

Casper

ProgressTalk.com Moderator
Staff member
you can use the quoter to be able to import the last line:
Code:
DEFINE STREAM sIn.
DEFINE VARIABLE cData AS CHARACTER   NO-UNDO.
DEFINE VARIABLE importfile AS CHARACTER   NO-UNDO.
CASE OPSYS:
 
     WHEN "UNIX"
      THEN 
        INPUT STREAM sIn THROUGH VALUE(SEARCH("quoter")) VALUE('"':U + SEARCH(importfile) + '"':U) > impfile.txt.
     WHEN "WIN32"
      THEN 
         OS-COMMAND SILENT VALUE(SEARCH("quoter.exe")) VALUE('"':U + SEARCH(importfile) + '"':U) > impfile.txt.
END CASE.
INPUT STREAM sIn FROM impfile.tmp.
REPEAT :
    ASSIGN cData = ?.
    IMPORT STREAM sIn cData.
    IF cData = ? THEN LEAVE.
    /* do you stuff */
END.


HTH,

Casper.
 

jhdz

New Member
Thanks Casper it work just great but I tried with the help but I did not find anything about the last values that you are using I did not understood
when you put this could you please explain me and thanks a lot :D :

Code:
OS-COMMAND SILENT VALUE(SEARCH("quoter.exe")) VALUE('"':U + SEARCH(importfile) + '"':U) > impfile.txt.


 

sphipp

Member
You could just add a line to the end of the file.

Try adding this code before the INPUT FROM Value(file) statement.

Code:
OUTPUT TO Value(file) APPEND.
PUT UNFORMATTED SKIP.
OUTPUT CLOSE.
 
Top