seq file read

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by rdenkers.

Ok, here we go.
I want to read a sequential file til the end of the file.
It must be read into a string so it can be displayed in a textbox.
Yes i admit, im only programming for 2 days in PB.
And my ( cobol) background doesnt really help me out here

the reference manual is not helping me very much to figure it out.

Anyone a good idea?
TIA.
rick




"Mensen struikelen niet over bergen, maar over molshopen."
Confucius
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> I want to read a sequential file til the end of the file.
> It must be read into a string so it can be displayed in a textbox.

Here you go:

Code: Select all

f$=OpenFileRequester("Select file to read","","All files (*.*)|*.*",0)
If ReadFile(0,f$)=0
  MessageRequester("Error","Couldn't read "+GetFilePart(f$),0)
Else
  While Eof(0)=0 ; Read each line until Eof (end-of-file).
    a$=ReadString() ; Read the next sequential line in the file.
    v$=v$+a$+Chr(13) ; Add it to v$ with a carriage-return [Chr(13)].
  Wend
  CloseFile(0)
  MessageRequester("File contents",v$,0)
EndIf

PB - Registered PureBasic Coder

Edited by - PB on 14 March 2002 01:49:26
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by rdenkers.

Pb,
Thanks for your assistance.
It works fine.

Rick


"Mensen struikelen niet over bergen, maar over molshopen."
Confucius
Post Reply