Android Question call a sub with the values of a variable

RandomCoder

Well-Known Member
Licensed User
Not sure how you mean?

B4X:
Sub example(val1 As Int, val2 As Int) ' declare any type of variable you need

Log("Value 1=" & val1 & " Value 2=" & val2)

End Sub

' call using...
example(variable1, variable2)
Or of course you could use a global variable inside your sub?
Or do you mean...

B4X:
Select var
    Case "example"
        example(variable1, variable2) 'sub call to example
    Case "example2"
        example2(str1, str2) 'sub call to example2
   Case Else
        anothersubname 'sub call to anothersubname
End Select
This is not quite dynamically calling of a Sub but I don't know of another way.
 

parijs

Active Member
Licensed User
Something like this Claus

Dim Variable As String
Variable = "Try"

Variable 'gall the sub

Sub Try
....
End Sub
 

DonManfred

Expert
Licensed User
No you can not do this

Maybe you can use a callsub or callsubdelayed

this works (but remember Try is a registered keyword. You can not use it as subname)

B4X:
    Dim Variable As String
    Variable = "TryThis"
    CallSubDelayed(Me,Variable) 'call the sub


Sub TryThis
Log("Trythis")
End Sub
 
Last edited:

RandomCoder

Well-Known Member
Licensed User
I could be wrong but I think you will need to use the Select Case statement or similar to program each call.
 
Top