Page 1 of 1

how to use createfile?

Posted: Fri Mar 17, 2017 9:43 am
by T4r4ntul4
How to use CreateFile() ?
It gives a compiler error: incorrect number of parameters
it needs a callback?

from the docs:

Code: Select all

If CreateFile(0, "Text.txt")         ; we create a new text file
    For a=1 To 10
      WriteStringN(0, "Line "+Str(a))  ; we write 10 lines (each with 'end of line' character)
    Next
    For a=1 To 10
      WriteString(0, "String"+Str(a))  ; and now we add 10 more strings on the same line (because there is no 'end of line' character)
    Next
    
    ExportFile(0, "text/plain")
    CloseFile(0)                      
  EndIf

Re: how to use createfile?

Posted: Fri Mar 17, 2017 10:39 am
by falsam

Code: Select all

Procedure onCreate()
EndProcedure

If CreateFile(0, "SomeText.txt", @onCreate())
  WriteStringN(0, "First line")
  WriteStringN(0, "Second line")
  ExportFile(0, "text/plain", #PB_LocalFile)  
EndIf
This callback is very strange

Re: how to use createfile?

Posted: Fri Mar 17, 2017 10:59 am
by T4r4ntul4
Where can this callback be for used, in createfile? Its empty and doesnt do much?

Re: how to use createfile?

Posted: Fri Mar 17, 2017 11:04 am
by falsam
The function is CreateFile(#File, FileName$, @Callback(), [Flags])

For me, this callback is useless. He is never called.

Code: Select all

Procedure onCreate()
  Debug "Hello" ; No hello
EndProcedure

If CreateFile(0, "SomeText.txt", @onCreate())
  WriteStringN(0, "First line")
  WriteStringN(0, "Second line")
  ExportFile(0, "text/plain", #PB_LocalFile)  
EndIf

Re: how to use createfile?

Posted: Fri Mar 17, 2017 11:09 am
by T4r4ntul4
i assume this is a bug then? callback is not necessary for this function?

Re: how to use createfile?

Posted: Fri Mar 17, 2017 11:11 am
by Peter
perhaps it's deprecated in further Versions, because it is not mentioned in the SB-Help?
Result = CreateFile(#File, Filename$ [, Flags])
only Fred knows...

Re: how to use createfile?

Posted: Fri Mar 17, 2017 11:16 am
by T4r4ntul4
yes i think so, in the IDE statusbar it still says it needs a callback, i think Fred forgot to edit it out in CreateFile() function

Re: how to use createfile?

Posted: Fri Mar 17, 2017 11:18 am
by falsam
Peter wrote:perhaps it's deprecated in further Versions, because it is not mentioned in the SB-Help?
Yes but if you do not put a callback, there is a compilation error.
T4r4ntul4 wrote:callback is not necessary for this function?
If you do not put a callback, there is a compilation error.
Compiler wrote:Lines 4 CreateFile() : Incorrect number of parameters.