[Implemented] Change file usage pointers inside commands

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] Change file usage pointers inside commands

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

Instead of using UseFile(#FileNumber), could we please have the standard BASIC way of doing it to save confusion and looping?? I've had lots of lockups till I figured this out.

Such as :

PrintN(1, $StufftoPrint$)

instead of

UseFile(1)
PrintN($StufftoPrint$)

Less code, More intuitive as far as past Basic experience goes. I open a lot of files you see.

:):)

Fangles

Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
Such as :

PrintN(1, $StufftoPrint$)

instead of

UseFile(1)
PrintN($StufftoPrint$)
That would be nice. A workaround, for the time being, could be a procedure
like the following:

Code: Select all

Procedure FPrintN(file,string$)
  UseFile(file)
  WriteStringN(string$)
EndProcedure
;
r=CreateFile(1,"c:\test1.txt")
r=CreateFile(2,"c:\test2.txt")
;
FPrintN(1,"this goes in test1.txt")
FPrintN(2,"this goes in test2.txt")
;
CloseFile(1)
CloseFile(2)
Edited by - PB on 13 December 2001 10:59:20
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

I also made some workaround with procedures like that:

Code: Select all

Procedure InitGadgets(GadgetMax)
  If InitGadget(GadgetMax) :  Else : End : EndIf
EndProcedure

Code: Select all

Procedure NewWindow(WinID,X,Y,sX,sY,Flag,Title$)
  If OpenWindow (WinID,X,Y,sX,sY,Flag,Title$) : Else : End : EndIf
EndProcedure

Code: Select all

Procedure NewGadgetList(WinID)
  If CreateGadgetList(WinID) : Else : End : EndIf
EndProcedure
because sometimes it is annoying to do:

Code: Select all

If InitGadget(GadgetMax)
  If OpenWindow (WinID,X,Y,sX,sY,Flag,Title$)
    If CreateGadgetList(WinID)
      ; lets go with the code...
      ; bla,bla
      ; how long is the following code?
    EndIf
  EndIf
EndIf
End
instead of:

Code: Select all

InitGadgets(#NbGadgetMax)
NewWindow(0, 200, 200, 320,240, #PB_Window_SystemMenu ,Name$)
NewGadgetList(WindowID())
; lets go with the code...
; bla,bla
; how long is the following code?
End
If something failes with InitGadget/OpenWindow/CreateGadgetList (and so on...) you can close your application anyway.
And if you wish an error message you can change your procedure to:

Code: Select all

Procedure InitGadgets(GadgetMax,ErrorMsg$)
  If InitGadget(GadgetMax) :  Else : MessageRequester("ERROR",ErrorMsg$,0) : End : EndIf
EndProcedure
or something like that.

IMHO it would make the code clearer, nicer and more up to date...

BTW: Why is there no 'IfNot' or a 'If Not' command?
For now it has to be:

Code: Select all

If CreateGadgetList(WinID) : Else : End : EndIf
Instead of:

Code: Select all

If Not CreateGadgetList(WinID) : End : EndIf


Have a nice day...
Franco

Edited by - franco on 13 December 2001 16:47:10
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
BTW: Why is there no 'IfNot' or a 'If Not' command?
For now it has to be:

Code: Select all

If CreateGadgetList(WinID) : Else : End : EndIf
Instead of:

Code: Select all

If Not CreateGadgetList(WinID) : End : EndIf
Why not using:

Code: Select all

If CreateGadgetList(WinID) = 0 : End : EndIf
. Anyway I will add the NOT operand.

Fred - AlphaSND
Post Reply