Android Question call a sub with the values of a variable

DonManfred

Expert
Licensed User
Longtime User
B4X:
dim mystring as String = "Hallo world"
MySub(mystring)
'
'
Sub MySub(myvalue as String)
  ' here you get he given value in myvalue
  log(myvalue)
end sub
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
Something like this Claus

Dim Variable As String
Variable = "Try"

Variable 'gall the sub

Sub Try
....
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime 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:
Upvote 0

RandomCoder

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