Android Question Resumable sub HELP!!!!

Ale_resource

Member
Licensed User
B4X:
Sub StartConnection As ResumableSub
    Funzioni.ScriviLog("Trying to connect to: " & Funzioni.ip)
    CloseExistingConnection
    clientSocket.Initialize("clientSocket")
    clientSocket.Connect(Funzioni.ip, Funzioni.port, 8000)
    Wait For ClientSocket_Connected (Successful As Boolean)
    If Successful Then
        Funzioni.ScriviLog("Connect a " & Funzioni.ip)
        'AStreams1.InitializePrefix(clientSocket.InputStream, False, clientSocket.OutputStream, "astreams1")
        AStreams1.Initialize(clientSocket.InputStream, clientSocket.OutputStream, "astreams1")
        Return True
    Else
        Funzioni.ScriviLog("Error Connection : " & LastException)
        Return False
    End If
End Sub

B4X:
dim c as Custom
c.Initialize
Wait For(c.StartConnection) Complete (Result As Boolean)
If Result = True Then
     'go ahead with command execution
Else
    'I have to repeat the sub StartConnection
End If

Hi, I have this sub which I then call this way, how do I repeat the command n times in case of a false result?
 

Ale_resource

Member
Licensed User
B4X:
Sub StartConnection As ResumableSub
    Funzioni.ScriviLog("Trying to connect to: " & Funzioni.ip)
    CloseExistingConnection
    clientSocket.Initialize("clientSocket")
    clientSocket.Connect(Funzioni.ip, Funzioni.port, 8000)
    Wait For ClientSocket_Connected (Successful As Boolean)
    If Successful Then
        Funzioni.ScriviLog("Connect a " & Funzioni.ip)
        'AStreams1.InitializePrefix(clientSocket.InputStream, False, clientSocket.OutputStream, "astreams1")
        AStreams1.Initialize(clientSocket.InputStream, clientSocket.OutputStream, "astreams1")
        Return True
    Else
        Funzioni.ScriviLog("Error Connection : " & LastException)
        Return False
    End If
End Sub

B4X:
dim c as Custom
c.Initialize
Wait For(c.StartConnection) Complete (Result As Boolean)
If Result = True Then
     'go ahead with command execution
Else
    'I have to repeat the sub StartConnection
End If

Hi, I have this sub which I then call this way, how do I repeat the command n times in case of a false result?
Any Help Please ??!!
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
@Erel is right, it creates confusion. Those who have problems with Resumale Subs may think of finding a solution to their problem and instead find a different question.
Furthermore, asking for help all the time is of no use, if they don't answer you it's because you have to give time

However, a solution could be this
B4X:
Dim N As Int = 0
Dim MaxN As Int = 5
Dim c As Custom
c.Initialize

Do While N<MaxN
  Wait For(c.StartConnection) Complete (Result As Boolean)
  If Result = True Then
     'go ahead with command execution
     N=MaxN+1
  Else
    'I have to repeat the sub StartConnection
    N=N+1
  End If
Loop
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I would change it a bit:
B4X:
Dim N As Int = 0
Dim MaxN As Int = 5


Do While N<MaxN
Dim c As Custom 'safer to start clean.
c.Initialize
  Wait For(c.StartConnection) Complete (Result As Boolean)
  If Result = True Then
     'go ahead with command execution
     N=MaxN+1
  Else
     Sleep(500) 'or more
    'I have to repeat the sub StartConnection
    N=N+1
  End If
Loop
 
Upvote 0

Ale_resource

Member
Licensed User
I would change it a bit:
B4X:
Dim N As Int = 0
Dim MaxN As Int = 5


Do While N<MaxN
Dim c As Custom 'safer to start clean.
c.Initialize
  Wait For(c.StartConnection) Complete (Result As Boolean)
  If Result = True Then
     'go ahead with command execution
     N=MaxN+1
  Else
     Sleep(500) 'or more
    'I have to repeat the sub StartConnection
    N=N+1
  End If
Loop
thanks and sorry for the mistake
 
Upvote 0
Top