B4J Question Wait For

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi everybody,
i would like to use wait for in the next condition, in Main i have first_sub and in code module i have second and third sub. First sub wait until second is finished and second wait until third is finished. Each sub return a value. If second and third sub are in main it works correct, if i move in code module never turn back to first sub. Can anybody advice me how can i solve? thank you. Attached the test app.
Main:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
    FirstSub
End Sub
Sub FirstSub
    Log("FirstSub started")
    Sleep(100)
    m.SecondSub
    Wait For SecondSub_Complete (x As Int)
    Log("FirstSub completed:"&x)
End Sub
Code module (m) :
B4X:
Sub SecondSub
    Log("SecondSub started")
    'Sleep(2000)
    thirdSub
    Wait For third_Complete (resp As Int)
    resp=resp+1
    Log("SecondSub completed"&resp)
    CallSubDelayed2(Me, "SecondSub_Complete",resp)
End Sub
Sub thirdSub
    Dim resp As Int=1
    Log("third started")
    'Sleep(2000)
    Log("Third completed:"&resp)
    CallSubDelayed2(Me, "third_Complete",resp)
End Sub
 

Attachments

  • testwaitfor.zip
    1.4 KB · Views: 154

OliverA

Expert
Licensed User
Longtime User
if i move in code module never turn back to first sub.
That's because in the SecondSub you forgot to change the target of the CallSubDelayed2 method. You had
B4X:
CallSubDelayed2(Me, "SecondSub_Complete",resp)
and it should have been
B4X:
CallSubDelayed2(Main, "SecondSub_Complete",resp)
since the SecondSub_Complete sub was in the Main module, not your code module (m) (that the Me was referencing). Just to a Log(Me) in Main and m to see what I mean.
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
That's because in the SecondSub you forgot to change the target of the CallSubDelayed2 method. You had
B4X:
CallSubDelayed2(Me, "SecondSub_Complete",resp)
and it should have been
B4X:
CallSubDelayed2(Main, "SecondSub_Complete",resp)
since the SecondSub_Complete sub was in the Main module, not your code module (m) (that the Me was referencing). Just to a Log(Me) in Main and m to see what I mean.
Thank you.
 
Upvote 0
Top