File Reading workout
Posted: Wed May 08, 2024 9:40 am
Hi,
for information, usually I do work with PB. Now I try to transfer PB to SB. So far so good.
In the moment I am facing a problem with correct position for action within the program.
Situation:
I open a file and read it line by line Which works fine. Each line will be processed by calling a php script by HTTPRequest().
During this procedure I block other buttons for action by DisableGadget(). I do this right after selecting the file by FileRequester(). It works fine.
The result of the HTTPRequest() should be stored in a structured variable.
At last I have to release buttons after the complete procedure of reading and handling the file content. (Here the problem starts)
I know SB is event driven. Unfortunately I cannot Debug in compiled application mode. I have to do it in compiled App mode because HTTPRequest() does not work in local Debug mode. As soon I run it in Debug Mode Message "HTTPRequest failed" happens and Program stopps.
Following the scheme of the procedures
My Question is, Where is the right Code Position to readout the MyStructure variable and to enable the Buttons after it is completely read.
Possibly I did something completely wrong due to the fact it is not PB. Over there it works
Thanks for your assistance
for information, usually I do work with PB. Now I try to transfer PB to SB. So far so good.
In the moment I am facing a problem with correct position for action within the program.
Situation:
I open a file and read it line by line Which works fine. Each line will be processed by calling a php script by HTTPRequest().
During this procedure I block other buttons for action by DisableGadget(). I do this right after selecting the file by FileRequester(). It works fine.
The result of the HTTPRequest() should be stored in a structured variable.
At last I have to release buttons after the complete procedure of reading and handling the file content. (Here the problem starts)
I know SB is event driven. Unfortunately I cannot Debug in compiled application mode. I have to do it in compiled App mode because HTTPRequest() does not work in local Debug mode. As soon I run it in Debug Mode Message "HTTPRequest failed" happens and Program stopps.
Following the scheme of the procedures
Code: Select all
structure first
a.s
b.s
endstructure
structure second
c.s
d.s
List result.first()
endstructure
Global MyStructure.second
Procedure HTTPGetEvent(success,result$,userdata)
if ParseJSON(#json,result$)
ExtractJSONStructure(JSONValue(#json),@MyStructure.second,second)
FreeJSON(#json)
Else
DisableGadget(#Button_xyz,0)
endif
endprocedure
Procedure ReadFileCallback(status,filename$,file,size)
Select status
While not EOF(#file)
string$ = ReadString(#file)
httpquery$ = "http://www..xyz.com?<key>=string$&<key>...."
HTTPRequest(#PB_HTTP_GET,URL_Encoder(httpquery$),"",@HTTPGetEvent(),0,httpheader())
Wend
;## If I start here with reading out the MyStructure.second structured variable it does not work
Disable Gadget(#Button_xyz,0) ;## Enabling Button immediately runs without waiting the above loop !??
endselect
endprocedure
Procedure OpenFileRequesterCallback()
If NextSelectedFile()
DisableGadget(#Button_xyz,1)
OpenFile(#file,SelectedFileID(),@ReadFileCallback(),#PB_LocalFile)
EndIf
endprocedure
Procedure chooseFileEvent()
OpenFileRequester,"",@OpenFileRequesterCallback())
endprocedure
Procedure GadgetEvents()
Select EventGadget()
Case #Button_start_file_procedure
chooseFileEvent()
endselect
endprocedure
Procedure main()
BindEvent(#PB_Event_Gadget,@GadgetEvents())
endprocedure
main()
Possibly I did something completely wrong due to the fact it is not PB. Over there it works
Thanks for your assistance