File I/O

Everything else that doesn't fall into one of the other categories.
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

File I/O

Post by MrTAToad »

It seems standard file I/O is now available, without the need for user selection or defined URL addresses :

Code: Select all

;
; ------------------------------------------------------------
;
;   SpiderBasic - File example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;


Procedure ReadCallback(Status, Filename$, File, Size)
  If Status = #PB_Status_Loaded
    Debug "File: " + Filename$ + " - Size: " + Size + " bytes"
    Debug "Reading first 3 lines:"
    
    ; Read the first 3 lines
    ;
    While Eof(0) = 0 And NbLine < 3 
      Debug ReadString(0)            
      NbLine+1
    Wend
    
    CloseFile(0)
    
  ElseIf Status = #PB_Status_Error
    Debug "Error when loading the file: " + Filename$
  EndIf
EndProcedure

;Procedure OpenFileRequesterCallback()
;  If NextSelectedFile()
;    ReadFile(0, SelectedFileID(), @ReadCallback(), #PB_LocalFile)
;  EndIf
;EndProcedure

Procedure ChooseFileEvent()
  ;OpenFileRequester("*.txt", @OpenFileRequesterCallback())
  ;If OpenFile(
  Debug "File Handle : "+Str(OpenFile(0, "canplay.sb", @ReadCallback(),0))
  
  Debug #PB_LocalFile
EndProcedure

OpenWindow(0, 0, 0, 300, 50, "Read file example", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 280, 30, "Choose a text file...")

;BindGadgetEvent(0, @ChooseFileEvent())
ChooseFileEvent()
Works fine locally and from a website
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: File I/O

Post by tj1010 »

You can use library functions for Cordova and have real file system access among a lot of other things.
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Re: File I/O

Post by MrTAToad »

I think what SpiderBasic provides should suffice.
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: File I/O

Post by tj1010 »

MrTAToad wrote:I think what SpiderBasic provides should suffice.
It's not persistent storage. I haven't tested much on mobile though they might have put it in.
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Re: File I/O

Post by MrTAToad »

It would depend on whether you want to upload data to a website, to avoid the possibility of the user's cache being cleared - if not, then it's certainly not totally persistent, although in most cases that shouldn't matter.
Post Reply