Android Question What is the difference between these two ways of calling a "sub"?

vecino

Well-Known Member
Licensed User
Longtime User
What is the difference? What is better?

CallSubDelayed3("","bbb",X,Y)
bbb(X,Y)

Thank you.

B4X:
Sub aaa_Click(X As Int, Y As Int)
'    CallSubDelayed3("","bbb",X,Y)
    bbb(X,Y)
End Sub

Sub bbb( X As Int, Y As Int )
    Log(X&" : "&Y)
End Sub
 

vecino

Well-Known Member
Licensed User
Longtime User
I don't think I understood what you were saying.
I probably didn't ask the question correctly.
Let's see now, what is the difference between the first way and the second way, which is more advisable?

B4X:
Sub btOK_Click(X As Int, Y As Int)
    CallSubDelayed3("","DoSomething",X,Y)
End Sub

Sub DoSomething( X As Int, Y As Int )
    Log(X&" : "&Y)
End Sub
B4X:
Sub btOK_Click(X As Int, Y As Int)
    DoSomething(X,Y)
End Sub

Sub DoSomething( X As Int, Y As Int )
    Log(X&" : "&Y)
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I don't think I understood what you were saying.
If you had:
B4X:
Sub btOK_Click(X As Int, Y As Int)
    CallSubDelayed3("","DoSomething",X,Y)
    Dim A As Int = 120
    Log(A)
End Sub

Sub DoSomething( X As Int, Y As Int )
    Log(X&" : "&Y)
End Sub

you would see the difference; using CallSubDelayed, before the execution of DoSomething the log of A would be executed, that is, all subsequent lines of che "calling sub", only at the end DoSomething would be executed.
 
Last edited:
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Now I understand :) Yes, that's what I assumed.
My question is exactly in the example I gave, the difference between using one method or the other.
 
Upvote 0

Sabotto

Well-Known Member
Licensed User
So ultimately

B4X:
Sub btOK_Click(X As Int, Y As Int)
    CallSubDelayed3("","DoSomething",X,Y)
    Dim A As Int = 120
    Log(A)
    'other instructions
    '''
End Sub

 'is equivalent to

Sub btOK_Click(X As Int, Y As Int)

    Dim A As Int = 120
    Log(A)
    'other instructions
    '''
    DoSomething(X,Y)

End Sub

It's correct?
 
Upvote 0
Top