GLBasic forum

Main forum => Bug Reports => Topic started by: spacefractal on 2011-May-07

Title: Readbyte and ReadLine issues?
Post by: spacefractal on 2011-May-07
I tried this code:

Code (glbasic) Select

LOCAL tem, ok
ok=OPENFILE(1,"test.ini", 1)
WHILE ENDOFFILE(1) = FALSE
READBYTE 1, tem
WEND


but I just got compile error:
Code (glbasic) Select

_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.7.861 SN:a001d9df - 3D, NET
Wordcount:5 commands
compiling:
C:\Users\SPACEF~1\AppData\Local\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\Users\SPACEF~1\AppData\Local\Temp\glbasic\gpc_temp0.cpp:41: error: invalid initialization of reference of type 'DGNat&' from expression of type 'DGInt'
D:/Programmer/GLBasic/Compiler/platform/Include/glb.h:1022: error: in passing argument 2 of `void __GLBASIC__::READBYTE(DGNat, DGNat&)'
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.2 sec. Time: 19:40
Build: 0 succeeded.
*** 1 FAILED ***


Also why is the readline limit to around 1024 chars? This cause xml hard to do with (this cause XMLParser not wokring (code snippet found in this forum), and that about LEN LINE=1023 didden't work quite well.... And even harder when ReadByte diddent work at all.
Title: Re: Readbyte and ReadLine issues?
Post by: Moru on 2011-May-07
I think "tem" needs to be an integer, not a float. Declare it like this:

global tem%
Title: Re: Readbyte and ReadLine issues?
Post by: spacefractal on 2011-May-07
checking later, its somewhere a bad error, sints its should been integer I actuelly use?

Howover the limited ReadLine function can been done same as this:

(Just edited to use as a function)
Code (glbasic) Select

FUNCTION LINEREAD$: FileNr
LOCAL chda$, L$=""
REPEAT
IF ENDOFFILE(FileNr) THEN BREAK
READSTR FileNr, chda$, 1
L$=L$+chda$
UNTIL ASC(chda$)=10
L$=TRIM$(L$)
RETURN L$
ENDFUNCTION


This read the whole line, not just the first kb of it. Mightbeen somewhere slowere, but its works.

PS. The thread can mightbeen move to code snippets (since its more a limit on the readline, not a bug)?
Title: Re: Readbyte and ReadLine issues?
Post by: MrTAToad on 2011-May-07
A variable without a % or $ is always defined as floating-point.  The READ/WRITE commands are somewhat unusual in that you can't use a float for the handle number and possibly for storing/writing values...
Title: Re: Readbyte and ReadLine issues?
Post by: spacefractal on 2011-May-07
ah, this due most other language I use allways use integer as standard, not floats. This can been a little bit of confuction.

Anyway, readline didden't work fully, but have a 1kb limit. I checked about the LEN(L$)=1023 as pointed in a another thread, but diddent work, and just add some garbages chars instead.

Instead I edited the post and then using READSTR instead. I not sure it was posted here, since I saw that, but fell free to move it out of bug thread (even ReadLine have a limit, but not a real bug).
Title: Re: Readbyte and ReadLine issues?
Post by: MrTAToad on 2011-May-07
Yes, Gernot has mentioned before that READLINE has a limit of 1023 bytes