B4J Question Wait For

Guenter Becker

Active Member
Licensed User
Longtime User
Good Day,

I like to do this
Example::
Private sub startTranslation(SourceLng as string, TargetLng as string, Text as string)
' check Internet
Wait for (checkInternet) Complete (Result as boolean)

If Result then
    Wait for Translate(SourceLng,TargetLng,text) Complete (trans as string)
    ' using clsGoogleTranslate
    label1.text = trans
end if
end sub
#####

private Sub checkInternet As ResumableSub
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://www.google.com")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        return= True
    Else
        return= False
    End If
    j.Release
End Sub

This will not work!
Error: Indifferent Declarations.
And in the checkInternet nothing is returned.

I tried several approches to solve the probleme but I don' get it done.
I think that anyone of you experts knows what I'm doing worng.
 

b4x-de

Active Member
Licensed User
Longtime User
We do not use return in an assignment in B4x. (This is not VBA.) After line 23 there should be a single return statement that returns the value you have stored in a local variable. But be aware that the variable may not be named "return".

B4X:
Wait For (j) JobDone(j As HttpJob)

Dim bolResult As Boolean
bolResult = j.Success

j.Release

Return bolResult
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Longtime User
Ok, will try it but thats only the half of the question answered. The 1st is what about using multiple wait for after the other as shown in my example. To avoid the error message that the second wait for is not meeting the 1st wait for.
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Longtime User
Thank you I think I found the failure. You are right it is possible to work with multiple wait for.
But the named Error will rise if you use different type of the result variable.
I change the wait for procedure following your example and I use only the the same result as string in all of the wait for used in the same sub and it is working! No mor error. Thank you.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
But the named Error will rise if you use different type of the result variable.
You just need to change the parameter name. You can set it to any name you like:
B4X:
Wait for (checkInternet) Complete (Result as boolean)

 Wait for Translate(SourceLng,TargetLng,text) Complete (OtherResult As String)
 
Upvote 0
Top