B4J Question Return Value from Resumable Sub

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

Via bluetooth, a write request is sent to a device using shell wait for (shl) shl_ProcessCompleted.
After successful completion, a read request is sent to a device using (again) shell wait for (shl) shl_ProcessCompleted.
The stdout of the read request is converted to a Double which is assigned to a global variable.

Pseudo Code (Temperature is a global double) defined in a Class
B4X:
Private Sub Temperature_GetRS As ResumableSub
   Temperature_Request
   Wait for Temperature_Request_Complete
   Temperature_Read
   Wait For Temperature_Read_Complete   
   Log($"Temperature: ${NumberFormat(Temperature, 0,2)}"$)
   Return Temperature
End Sub

Question: Is there a way to return the result from the sub?
The intention is to use the sub Temperature_Get from other classes, i.e. T = MyClass.Temperature_Get

Tried below but getting an error "Resumable return type must be resumable sub".
B4X:
Sub Temperature_Get As Double
   Dim rs As ResumableSub = Temperature_GetRS
   Wait For(rs) Complete (Result As Double)
   Temperature = Result
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is there a way to return the result from the sub?
Yes.
1. Note that you can call it like this:
B4X:
Wait For (Temperature_GetRS) Complete (Result As Double)

2. The problem is in Temperature_Get. It is a resumable sub by itself. So the return type cannot be Double. Just remove it as you are not returning anything anyway.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…