correct place for closefile

BlitzPlus Forums/BlitzPlus Programming/correct place for closefile

Timjo(Posted 2007) [#1]
Hmmmm...Which is the correct place for closefile:

myfile=openfile("filename")
if myfile<>0
load some stuff
endif
closefile myfile

OR:

myfile=openfile("filename")
if myfile<>0
load some stuff
closefile myfile
endif

I'm thinking that if the file was unable to be opened then there's no need to close it (sounds obvious I know) so the second option is right, but I'm not completely certain - any help welcome ..Thanks.


JazzieB(Posted 2007) [#2]
Before EndIf. If the file didn't open, then there's no need to close it, as it never opened in the first place.


CS_TBL(Posted 2007) [#3]
btw, minor detail: In your IF statement: "<>0" can be left out. "If <value>" means "If True", and True is "<>0".


Matty(Posted 2007) [#4]
The first example (with the closefile outside of the if..then construct) will result in a MAV if the file didn't exist in the first place.


Timjo(Posted 2007) [#5]
Thanks for the help - much appreciated... Timjo.

(p.s. - it's probably something obvious - but what does MAV stand for ?)


CS_TBL(Posted 2007) [#6]
memory access violation