Open to read failed?

Post your coding questions such as 'how to' here.
Post Reply
coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

Open to read failed?

Post by coolw »

^^^ After a few seconds of not typing anything, open to read fails. Everything works, just crashes after a few seconds. Not the complete code!! (Non essential code ommited)

Code: Select all

ViewBook1:
a=OpenToRead("People.txt")
Cls
Print ""
Search$=Input("Find:")
If Search = "" Then
    If Not EOF(a) Then
        iLine$ = ReadLine(a)
        Print iLine
        Drawscreen
        Goto ViewBook1
    Else
        Goto ViewBook1
    EndIf
Else
    If Not EOF(a) Then
    iLine$ = ReadLine(a)
    EndIf
EndIf
DrawScreen
Goto ViewBook1
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)
otto90x
Advanced Member
Posts: 349
Joined: Mon Aug 27, 2007 9:00 pm
Location: Lapinjärvi, Finland
Contact:

Re: Open to read failed?

Post by otto90x »

It seems to me that you don't close file after reading it so before going to viewbook1 close file using command

Code: Select all

CloseFile a
But I don't really get how your code is going to work and why you are checking if the file is running out since you start it all over again, when you go to viewbook1. This is how you might want to do, or at least it's my vision of your code.

Code: Select all

viewbook1:
Cls
Print ""
Repeat
    Search$=Input("Find:")
    DrawScreen
Until KeyHit(cbkeyreturn) 
CloseInput

a=OpenToRead("People.txt")

While Not EOF(a)
    If Search$ = "" Then
        iLine$ = ReadLine(a)
        Print iLine
    EndIf
Wend 
WaitKey

closefile a

Goto viewbook1
Otto Martikainen a.k.a. MetalRain, otto90x, kAATOSade.
Runoblogi, vuodatusta ja sekoiluja.
coolw
Newcomer
Posts: 39
Joined: Wed Aug 29, 2007 11:17 pm
Location: West Virginia
Contact:

Re: Open to read failed?

Post by coolw »

Well I am trying to get it so that if there is no Search, it lists everything in the file, otherwise, I want it to find a certain string in the file. I can't seem to get it right... :twisted:
My car game! (WIP)
viewtopic.php?f=18&t=53

Code: Select all

Coolw is the best! :)
Post Reply