I'm new to spider basic, so please excuse this simple question.
Perhaps somebody can help me with this problem: I want to open a file and the read data shall be put in an Array. This does not work. The Array is empty. How can I fill an Array with data read from a file?
Greetings,
Chris
Code: Select all
Global Dim Daten.s (10)
Procedure ReadCallback(Status, Filename$, File, Size)
If Status = #PB_Status_Loaded
Debug "File: " + Filename$ + " - Size: " + Size + " bytes"
; Read the first 10 lines
;
While Eof(0) = 0 And NbLine < 10
s$ = ReadString(0)
NbLine+1
Daten(NbLine) = s$
Wend
CloseFile(0)
ElseIf Status = #PB_Status_Error
Debug "Error when loading the file: " + Filename$
EndIf
EndProcedure
Procedure OpenFileRequesterCallback()
If NextSelectedFile()
OpenFile(0, SelectedFileID(), @ReadCallback(), #PB_LocalFile)
EndIf
EndProcedure
Procedure ChooseFileEvent()
OpenFileRequester("*.txt", @OpenFileRequesterCallback())
EndProcedure
OpenWindow(0, 0, 0, 300, 50, "Read file example", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 280, 30, "Choose a file...")
BindGadgetEvent(0, @ChooseFileEvent())
For i = 1 To 10
Debug Daten(i)
Next