I am reading lines from a text file, and adding them to a list.
How can I wait/halt my program until the read-loop has finished?
(example code modifies from help file)
Code: Select all
Global.s NewList t()
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
AddElement(t())
t()=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())
ForEach t()
Debug t()
Next
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())