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

File I/O

by MrTAToad Fri Jun 02, 2017 7:23 pm

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: 186
Joined: Wed May 27, 2015 1:36 pm

Re: File I/O

by tj1010 Sat Jun 03, 2017 9:20 am

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

Re: File I/O

by MrTAToad Sat Jun 03, 2017 7:21 pm

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

Re: File I/O

by tj1010 Sun Jun 04, 2017 12:02 pm

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

Re: File I/O

by MrTAToad Sun Jun 04, 2017 12:20 pm

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.
Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests