Android Question Sub Object?

Alessandro71

Well-Known Member
Licensed User
Longtime User
Is there a way to use a Sub as an Object?
Actually I'm using some code like this:
B4X:
    Select index
        Case 1
            function_a
        Case 2
            function_b
        Case 3
            function_c
    End Select
I'm wondering if I could create a map like this
B4X:
    Dim functionmap As Map = CreateMap( _
        1: function_a, _
        2: function_b, _
        3: function_b _
    )
so it would be possible to select the right Sub only by a Get and calling it
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
Do I have the side effect of the Sub being actually called only at the next event loop iteration instead of being called immediately?
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
I see that CallSub can't be used for Code modules (that's my use case)
It's also not clear if I can get the return value of the called Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I see that CallSub can't be used for Code modules (that's my use case)
It's also not clear if I can get the return value of the called Sub
You can "transform" your code module to a class module. Create a new class, move all stuff (variables, subs) to this class.
Once you have an instance of that class (a variable), you can call its sub as wrote and get results.

Dim Result As Int = CallSub2(InstanceName, mapSubs.Get("MyRoutine"), 5)
 
Upvote 0
Top