Restored from previous forum. Originally posted by Fangbeast.
I've tried for hours to get ReadString to return data from any file at all. I tested the display routing by feeding it random strings, that works fine. I tested the OpenFile command and it is returning a value indicating the file is open. I've tried with 5 different text files, cannot return data from any of them. The text files exist.
I can open the files and read data using PowerBasic's Line Input command, the ReadString() equivalent so I know the files read fine.
I'm out of ideas and exhausted. Anyone have any ideas??? (I'm going to bed before I fall over) Fangles
Fangles
Can't get ReadString() to return anything
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
Maybe post your code so we can see why it's not working.
A somple Read File routine might look something like this...
Maybe post your code so we can see why it's not working.
A somple Read File routine might look something like this...
Code: Select all
NewList dat.s()
ClearList(dat())
If ReadFile(0,"datafile.txt")
While eof()=0
AddElement(dat())
dat()=Readstring()
Wend
EndIf
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by wavemaker.
I had the same problem with ReadString(), and decided to use ReadByte(), which works fine:
NewList dat.s()
string$=""
ClearList(dat())
If ReadFile(0,"datafile.txt")
While eof()=0
a=ReadByte()
Select a
Case 10 ; String end for Unix-like text files; must test for a following
13 in PC-like ones
dat()=string$
AddElement(dat())
string$=""
Default
string$ = string$ + chr(a)
EndSelect
Wend
EndIf
I think it should work, I haven't tested it <)
Juan Calderón Alonso
Registered user
I had the same problem with ReadString(), and decided to use ReadByte(), which works fine:
NewList dat.s()
string$=""
ClearList(dat())
If ReadFile(0,"datafile.txt")
While eof()=0
a=ReadByte()
Select a
Case 10 ; String end for Unix-like text files; must test for a following
13 in PC-like ones
dat()=string$
AddElement(dat())
string$=""
Default
string$ = string$ + chr(a)
EndSelect
Wend
EndIf
I think it should work, I haven't tested it <)
Juan Calderón Alonso
Registered user