Bug? Complete keyword

Alessandro71

Well-Known Member
Licensed User
Longtime User
By pure chance I've found a line in my code that wasn't marked as as syntax error and compiles fine:

B4X:
Wait For (sf) Completa (Result As Int)
'Completa instead of Complete
 

LucaMs

Expert
Licensed User
Longtime User
By pure chance I've found a line in my code that wasn't marked as as syntax error and compiles fine:

B4X:
Wait For (sf) Completa (Result As Int)
'Completa instead of Complete
Are you sure?

1.gif
 

Alessandro71

Well-Known Member
Licensed User
Longtime User

pretty sure
B4X:
    Dim sf As Object = B4XPages.MainPage.Msg.ShowMsgbox2Async("Are you sure you want to restart?", "Warning", "Yes", "", "No")
    Wait For (sf) Completa (Result As Int)

where the resumable sub is as follows
B4X:
Public Sub ShowMsgbox2Async(message As Object, title As Object, positive As String, cancel As String, negative As String) As ResumableSub
    Dim msg As String = message
    WriteLog(msg.Replace(CRLF, "|"))
    
    Dim sf As Object
    sf = xui.Msgbox2Async(message, title, positive, cancel, negative, Null)
    Wait For (sf) Msgbox_Result (Result As Int)

    Select Result
        Case xui.DialogResponse_Positive
            WriteLog("user answer positive")
        Case xui.DialogResponse_Negative
            WriteLog("user answer negative")
        Case xui.DialogResponse_Cancel
            WriteLog("user answer cancel")
        Case Else
            WriteLog("Unknown user answer")
    End Select
    
    Return Result
End Sub
 

agraham

Expert
Licensed User
Longtime User
Using the original example

No Error:
Dim sf As Object = B4XPages.MainPage.Msg.ShowMsgbox2Async("Are you sure you want to restart?", "Warning", "Yes", "", "No")
Wait For (sf) Completa (Result As Int)


Error:
Wait For (B4XPages.MainPage.Msg.ShowMsgbox2Async("Are you sure you want to restart?", "Warning", "Yes", "", "No")) Completa (Result As Int)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is not a bug.
The only case where the compiler will raise an error is when you call a resumable sub.
In other cases the compiler cannot know the correct event name.
B4X:
Wait For (MyResumableSub) Completa (x As Y) 'error here
Wait For (AnythingElse) Completa (x As Z) 'this is valid
 

LucaMs

Expert
Licensed User
Longtime User
This is not a bug.
The only case where the compiler will raise an error is when you call a resumable sub.
In other cases the compiler cannot know the correct event name.
B4X:
Wait For (MyResumableSub) Completa (x As Y) 'error here
Wait For (AnythingElse) Completa (x As Z) 'this is valid
I did not understand a fife ?:confused:

The event that Wait For awaits is the first name (AnythingElse, in the example), isn't it?

By the way, now I can't get something to work that I did in the past; I used CallSub2 or CallSubDelayed2 "invoking" the name of the non-existent routine, it was only the name of the first "parameter" of the "Wait For".

I try to re-read the thread about the Resumables but I'm afraid I need different explanations.
 

LucaMs

Expert
Licensed User
Longtime User
The event that Wait For awaits is the first name (AnythingElse, in the example), isn't it?
No. This is the "sender filter" object.

[Disregard the fact that the following example looks stupid; it's part of an old question]
B4J:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
   
    Wait For TaskCompleted(Result As String)
    Log(Result)
End Sub

Sub Button1_Click
    ' If I used CallSub2 instead of CallSubDelayed2, the project would crash.
    ' Why? <---
    CallSubDelayed2(Me, "TaskCompleted", "Done")
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
[Disregard the fact that the following example looks stupid; it's part of an old question]
This is not related to this thread.
The fact that it crashes in debug mode is a bug. With that said, it is recommended to use CallSubDelayed to raise events that are expected to be caught with Wait For. Otherwise there could be cases where the event is missed.
 

LucaMs

Expert
Licensed User
Longtime User
it is recommended to use CallSubDelayed to raise events that are expected to be caught with Wait For.
There were two issues. The first, in the source, CallSub, ok, I understand. The second... you also call (define) it "event" now (that TaskCompleted) [just above].
The event that Wait For awaits is the first name (AnythingElse, in the example), isn't it?
but below you call (define) "event" the "second part" ("CompletA").
In other cases the compiler cannot know the correct event name.

I read the thread about resumables again but, although I always manage to use them, not everything is clear to me.
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
This is not a bug.
The only case where the compiler will raise an error is when you call a resumable sub.
In other cases the compiler cannot know the correct event name.
B4X:
Wait For (MyResumableSub) Completa (x As Y) 'error here
Wait For (AnythingElse) Completa (x As Z) 'this is valid
A good reason for not using an object to store the result of a resumable sub unless necessary (where ”necessary” may only be checking the result later in the code, instead of immediately?)
 
Top