Problem In Reading A Text File

KrisM

Member
Suppose I am using this code to read a text file :

Code:
DEFINE VARIABLE inputLine AS CHARACTER   NO-UNDO.
DEFINE STREAM sin.

input stream sin from T:/demo.txt.
repeat:
    import stream sin unformatted inputLine.
    ...
end.
input stream sin close.

Suppose the text file contains some text like :

A
B
C
D

with the last line not being terminated with a carriage return or line feed character.

What progress reads is

A
B
C
C

So the last line is not read correctly.
Is Progress aware of this issue ? I think this issue already exists for a long time.
Do you know of a workaround for this issue ?
 
Suppose I am using this code to read a text file :

Code:
DEFINE VARIABLE inputLine AS CHARACTER   NO-UNDO.
DEFINE STREAM sin.

input stream sin from T:/demo.txt.
repeat:
    import stream sin unformatted inputLine.
    ...
end.
input stream sin close.

Suppose the text file contains some text like :

A
B
C
D

with the last line not being terminated with a carriage return or line feed character.

What progress reads is

A
B
C
C

So the last line is not read correctly.
Is Progress aware of this issue ? I think this issue already exists for a long time.
Do you know of a workaround for this issue ?

Workaround: Add a carriage return or line feed to your file.
OUTPUT TO yourfile.txt APPEND.
PUT SKIP. or PUT CONTROL CHR(13) CHR(10).
OUTPUT CLOSE.
 

Cringer

ProgressTalk.com Moderator
Staff member
What Progress version? 10.2B or later you can use a LONGCHAR.
COPY-LOB from file MyFile to object MyLongCharVar.
Then you can parse the contents just as you would any character variable. So long as the file isn't massive it's often a lot better than streams as you aren't limited to a linear reading of the contents.
 
Top