read from file

Blitz3D Forums/Blitz3D Beginners Area/read from file

ingenium(Posted 2007) [#1]
This piece of code doesn't work... why?

If num = 0
 file = ReadFile("aaa.txt")
 While Not Eof(file)
  tex1.tex = New tex
  tex1\let = ReadString$(file)
 Wend
 CloseFile(file)
EndIf 
num = 1

For tex1.tex = Each tex
 Text x,y,tex1\let
 x = x + 8
 If x > 455 Then y = y + 15 : x = 30
Next
x = 30
y = 30


The readstring$ command gives me an error.

P.s. the file exists


(tu) sinu(Posted 2007) [#2]
you need to use readline if you haven't used writestring to write strings in the file.
Readline reads each line from the start, whereas readstring reads a string where the first values holds the length, i think, of the string.


ingenium(Posted 2007) [#3]
But using readline i see no way to add a return between some words... I need this text to be formatted... I hope i am clear. Is there a way to add a return in the middle of a line?


GfK(Posted 2007) [#4]
I don't see a type declaration?

What error do you get? (To save time, if its "Memory access violation", turn Debug on, then try the code again).


ingenium(Posted 2007) [#5]
This is a "piece" of code Gfk...
I have a Memory access violation and the debug is on... :(


GfK(Posted 2007) [#6]
Then what Sinu said is most likely correct.

Even if you managed to get your text into Blitz, none of the text commands (Text, Print etc) support carriage return or linefeeds anyway, so you'd still have to parse it yourself.


ingenium(Posted 2007) [#7]
Sob. OK thanks anyway.