CurrentFile()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Tomio
Enthusiast
Enthusiast
Posts: 291
Joined: Sun Apr 27, 2003 4:54 pm
Location: Germany

CurrentFile()

Post by Tomio »

i=CurrentFile() .....gives back the number of the file currently in use.
i=0 if no file is in use.

With this you could open/close/... files everywhere without having to track
files in use, e.g.:

Procedure abc()
i=CurrentFile()
OpenFile(...)
...do something
CloseFile()
If i<>0: UseFile(i): Endif
EndProcedure

.../tomio
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

Why don't you do like that:

Code: Select all

Global currentfile.l

procedure blah()
openfile(x)  ;you will probably know which file you are going to open
currentfile=x  ;just keep its number in a variable
...
closefile(x)
if currentfile<>0:usefile(currentfile):endif
EndProcedure
I know it would be easier with "currentfile()" but it's not that necessary.

By the way:
Tomio wrote:i=CurrentFile() .....gives back the number of the file currently in use.
i=0 if no file is in use.
You can load a #0 file.

Code: Select all

OpenFile(0,"myfile.bla")

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

Sorry for double posting. :oops: Now I realize exactly what you meant in your procedure. So, before you start complaining I didn't understand, here's another code as an example:

Code: Select all

Global currentfile.l

procedure abc()  ;abc as you named it :)
OpenFile(...) 
...do something 
CloseFile() 
If currentfile=>0: UseFile(currentfile): Endif ;you should get current file before hand or use as a parameter in the procedure.
EndProcedure 

... two hundred thousand lines of code

openfile(a)  ;Oops, you opened a file, get its number
currentfile=a

... more code

DisplaySprite(0,x,y)
DisplayPaletteSprite(1,x,y,2) ; this doesn't exist yet...
abc() ; after "abc", current file should be the same. 
Indeed, it would be annoying to get the file number every time you open a new file, mainly if your code is already too long and you have to change it... Alright, I agree, CurrentFile() could be useful. :wink:

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
Tomio
Enthusiast
Enthusiast
Posts: 291
Joined: Sun Apr 27, 2003 4:54 pm
Location: Germany

Post by Tomio »

Fou-Lu wrote:... Alright, I agree, CurrentFile() could be useful. :wink:
Thanks Fou-Lu for the assistance!

../tomio
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

I think than all current things will disappear with the next major release of PB, so a such command will probably never happen.
Post Reply