Record to many when reading file

Windows specific questions.
BasicJan
Posts: 46
Joined: Aug 30, 2005 20:09
Location: Netherlands

Record to many when reading file

Postby BasicJan » Aug 14, 2006 15:38

An old error has occurred again (found in FreeBasic version 0.17, found before in 0.13 or so).
If an external file is read, one record to many is found.

Try next code.

Code: Select all

********** FILE: MAINPROG.BAS **********
DIM LvInput
DIM LvCounter

LvCounter=0
OPEN "TEST.TXT" FOR INPUT AS #1
DO WHILE NOT EOF(1)
  INPUT #1,LvInput
  LvCounter=LvCounter+1
LOOP
CLOSE #1
CLS
PRINT "Number of records found: ",LvCounter
SYSTEM


********** FILE: TEST.TXT **********
1
2
<EOF>
v1ctor
Site Admin
Posts: 3801
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Postby v1ctor » Aug 14, 2006 18:47

Fixed in CVS, EOF should always work now in text-mode. A regression test based in your example was added too, thanks.
Confuzed
Posts: 4
Joined: Aug 21, 2006 3:44

A-ha!

Postby Confuzed » Aug 21, 2006 3:48

I didn't think I was going nuts. Spent an hour trying to figure out why my app wouldn't stop the parsing loop on the input text file. I dissected everything until I gave up and was going to post for help here!

When is this fix due to hit a downloadable version of Windows binary? I browsed the CVS but didn't see any fbc.exe.

My app is on hold until I can get it to detect EOF.
counting_pine
Site Admin
Posts: 6230
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Aug 21, 2006 12:10

anonymous1337 has a CVS build of FreeBASIC that he updates every day or so. You can get it here:
http://www.qbasic.com/wbb/filebase_entry.php?entryid=77
coderJeff
Site Admin
Posts: 3343
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Postby coderJeff » Aug 21, 2006 13:02

counting_pine wrote:anonymous1337 has a CVS build of FreeBASIC that he updates every day or so. You can get it here:
http://www.qbasic.com/wbb/filebase_entry.php?entryid=77


Can people actually get it from there? I only ever get "Access Denied" on that site, even when trying to register a new login.
counting_pine
Site Admin
Posts: 6230
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Aug 21, 2006 13:29

To be honest, it's been a while since I tried, I usually just use the official testing releases.
Well, I just tried it. It downloaded OK without any "Access Denied" problems (I didn't have to register or login.) The only thing was that it didn't put an extension on the file, but it seems to be a valid rar archive.
I'm afraid I couldn't say why you'd be having difficulties. Is anyone else having that problem?
Jerry Fielden
Posts: 165
Joined: May 27, 2005 14:14
Location: Marshall, Oklahoma, USA
Contact:

Postby Jerry Fielden » Aug 21, 2006 13:31

I just tried it without login and it downloaded alright.

You might check Firewall or Malware or antivirus programs for blockings.

Zone alarm used to block every download site for me.
badmrbox
Posts: 659
Joined: Oct 27, 2005 14:40
Location: Sweden
Contact:

Postby badmrbox » Aug 21, 2006 13:47

Can people actually get it from there? I only ever get "Access Denied" on that site, even when trying to register a new login.
It sounds strange O_o but as Jerry said, check your firewall and stuff and try again. It shouldn't be any problems at all.
coderJeff
Site Admin
Posts: 3343
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Postby coderJeff » Aug 21, 2006 13:59

Guess it's just me then. This is the only page I get:
http://www.execulink.com/~coder/tmp/qbasic_noacess.png

I don't think it's the firewall. I tried opening a few well known ports and responding to pings from internet side, and doing a bunch of other things to compromise my system I shouldn't have to. No luck.

I hope most users can download it.
badmrbox
Posts: 659
Joined: Oct 27, 2005 14:40
Location: Sweden
Contact:

Postby badmrbox » Aug 21, 2006 16:39

That screen does only appear when you are trying to reply in forums where you have to be registred to reply. It should most definitely not appear when you are trying to register... :S
Confuzed
Posts: 4
Joined: Aug 21, 2006 3:44

Unfortunately - no go

Postby Confuzed » Aug 23, 2006 18:14

counting_pine wrote:anonymous1337 has a CVS build of FreeBASIC that he updates every day or so. You can get it here:
http://www.qbasic.com/wbb/filebase_entry.php?entryid=77


Ya tried that and get same result.

I've even tried a quick and dirty test with a known good text file:

Code: Select all

rem Test for FreeBASIC 0.17-unstable (Win32) EOF routine functionality

dim a as string
dim i as integer

a = ""
open "httpd.conf" for input as #5
do
    do
        line input #5, a
        i=i+1: print i;: print " " + a
        if i = 1000 goto goodbye
    loop until left$(lcase$(a),12)="<virtualhost"

    do
        line input #5, a
        if lcase$(a)<>"</virtualhost>" then print a
    loop until lcase$(a)="</virtualhost>"
    print: print "================":print
loop until eof(5)
close #5

goodbye:
PRINT "press q to quit"
DO
LOOP UNTIL INKEY$ = "q"
end

You'll notice that the only reason it gets to the label "goodbye" is because of the counter (i).

I've moved the until EOF(5) from the DO keyword to the LOOP keyword - same problem.
counting_pine
Site Admin
Posts: 6230
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Aug 23, 2006 22:54

That code works fine for me. I made a file by doing:

Code: Select all

open "httpd.conf" for output as #1
    print #1, !"<virtualhost\n</virtualhost>\n";
close #1

And the program worked fine with it.
Obviously, "</virtualhost>" would have to be the last line in the file to work properly.

(EDIT: updated code to actually work)
Confuzed
Posts: 4
Joined: Aug 21, 2006 3:44

Postby Confuzed » Aug 25, 2006 5:32

counting_pine wrote:Obviously, "</virtualhost>" would have to be the last line in the file to work properly.


That, unfortunately, is not a guarantee with either my application nor with my example. There is every likelyhood that there will be more data beyond the last "</virtualhost>" or whatever.
In the case of my example, a "<virtualhost>" block can be anywhere in the httpd.conf file. Multiple such blocks can be scattered all over the file. Why you would do that is beyond me but since it is possible I must account for it. Same with my application. The data I'm seeking is located in a block and can be located anywhere in the file in any order. Neither the httpd.conf example file nor my application data file can be sorted as they are live files. Even so, a sort would require the EOF to function.
counting_pine
Site Admin
Posts: 6230
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Aug 25, 2006 11:44

If "</virtualhost>" isn't the last line in the file, then your program will get stuck in the first inner Do loop, until i reaches 1000. (Unless there is a stray "<virtualhost" later on without an equivalent "</virtualhost>", in which case it will get stuck forever in the second Do loop.)
The "Loop Until Eof(5)" line will only exit if it hits the EOF straight after "</virtualhost>". This seems to work whether or not there's a line break directly after it.
Confuzed
Posts: 4
Joined: Aug 21, 2006 3:44

Postby Confuzed » Sep 01, 2006 20:38

Thanks. That pointed me in the right direction. I was getting hung up on the EOF issue and not evaluating the logic of the DO...LOOP. Here's the working code in case it helps anyone else:

Code: Select all

Rem Test for FreeBASIC 0.17-unstable (Win32) EOF routine functionality

dim a as string
dim i as integer

a = ""
open "httpd.conf" for input as #5
do
    do
        line input #5, a
        rem "i" just makes sure we don't end up in an endless loop
        i=i+1: print i;: print " " + a
        if i = 1000 goto goodbye
    loop until left$(lcase$(a),12)="<virtualhost" or eof(5)

    do
        line input #5, a
        if lcase$(a)<>"</virtualhost>" then print a
    loop until lcase$(a)="</virtualhost>" or eof(5)
    print:print "================":print
loop until eof(5)
close #5

goodbye:
PRINT "press q to quit"
DO
LOOP UNTIL INKEY$ = "q"
end

Return to “Windows”

Who is online

Users browsing this forum: No registered users and 3 guests