GLBasic forum

Main forum => GLBasic - en => Topic started by: okee on 2011-Feb-06

Title: How can i check if a file is open
Post by: okee on 2011-Feb-06
If i do

Code (glbasic) Select
IF OPENFILE(1, WordFile$, 1)
     print "Open",1,1
else
      print "Couldnt open" + WordFile$, 1,10
endif


This tries to open a file and returns a message if it can't
If the file opens succesfully, is there any way later on to
check that the file is open, say something like ISFILEOPEN(1)
Title: Re: How can i check if a file is open
Post by: MrTAToad on 2011-Feb-06
You shouldn't really need to check to see if a file is opened later on

However, you could either use a flag variable (set it to TRUE if its open), and set it to FALSE when the file is closed

or

you can use a TRY/CATCH/THROW block
Title: Re: How can i check if a file is open
Post by: okee on 2011-Feb-06
Ok i just thought i'd overlooked a command.
Just on another note is there any reason why you cannot assign
a channel number greater than 7 to a file, while i was debugging
i put in a channel number 8 which caused an error.
Title: Re: How can i check if a file is open
Post by: MrTAToad on 2011-Feb-06
Quote from: okee on 2011-Feb-06
Ok i just thought i'd overlooked a command.
Just on another note is there any reason why you cannot assign
a channel number greater than 7 to a file, while i was debugging
i put in a channel number 8 which caused an error.
Gernot has limited the file handle numbers to between 0 and 7
Title: Re: How can i check if a file is open
Post by: MrTAToad on 2011-Feb-06
Quotedepends on the environment.  An app wants to open a server based file, one that potentially was opened by another user already, might find it useful to do some checking first
Good point there!  I dont know how Sqlite does it, but Pervasive would set various bytes within the database file to a certain value...