[Wish] CallSub4

Dominex

Active Member
Licensed User
Longtime User
It would be very very handy to have also CallSub4 because it is be essential for passing data of touch events (Action, X, Y).

B4X:
CallSub4 (Component As Object, Sub As String, Argument1 As Object, Argument2 As Object, Argument3 As Object) As String

CallSub4("Main","Activity_Touch",Action,X,Y)
 

Informatix

Expert
Licensed User
Longtime User
It would be very very handy to have also CallSub4 because it is be essential for passing data of touch events (Action, X, Y).

B4X:
CallSub4 (Component As Object, Sub As String, Argument1 As Object, Argument2 As Object, Argument3 As Object) As String

CallSub4("Main","Activity_Touch",Action,X,Y)

Use my library CallSubExtended provided with ULV. You're not limited by the number of arguments.
 

Eduard

Active Member
Licensed User
Longtime User
As a workaround you could make a class than can hold 4 arguments

You can then pass this class (with callsub2).
 

Dominex

Active Member
Licensed User
Longtime User
As a workaround you could make a class than can hold 4 arguments

You can then pass this class (with callsub2).

Thanks for the idea, but I did not understand how to put it into practice. Pass a class? Can you do?
 

mc73

Well-Known Member
Licensed User
Longtime User
As a workaround, you can send a combined string and regex.split it to get the arguments.
 

Penko

Active Member
Licensed User
Longtime User
I made a small example for you. I hope I have correctly understood your problem.

What I am demonstrating is the use of classes as data containers. This ensures you flexibility by adding more items to the class in the feature.

You will see two buttons - the first uses CallSub2 and calls a method within the very same Activity1.

The second button benefits from the CallSubDelayed2 command and opens Activity2 by calling its method customLoader2.

Both return the same message box information.
 

Attachments

  • CallSubSample.zip
    8.6 KB · Views: 265

Dominex

Active Member
Licensed User
Longtime User
I made a small example for you. I hope I have correctly understood your problem.

What I am demonstrating is the use of classes as data containers. This ensures you flexibility by adding more items to the class in the feature.

You will see two buttons - the first uses CallSub2 and calls a method within the very same Activity1.

The second button benefits from the CallSubDelayed2 command and opens Activity2 by calling its method customLoader2.

Both return the same message box information.

Thank you for your example, but it is not what I need. I need a way to call a sub with three arguments, I want called "Activity_Touch".
 

Eduard

Active Member
Licensed User
Longtime User
B4X:
'Class module ArgumentsContainer
Sub Class_Globals
   Public argument1 As Object
   Public argument2 As Object
   Public argument3 As Object
   Public argument4 As Object
   Public argument5 As Object
End Sub

B4X:
Dim argc as ArgumentsContainer
argc.initialize
argc.argument1="one"
argc.argument2="two"
argc.argument3="three"
argc.argument4="four"
callsub2(Main,"function_name",argc)
note that any of the argments kan be an argumentscontainer as well....

the example of Penko is exactly what I mean.

B4X:
Sub function_name(argc as ArgumentsContainer)
 dim x as string
 x=argc.argument4
 msgbox(x,"this is argument4)
end sub
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
B4X:
'Class module ArgumentsContainer
Sub Class_Globals
   Public argument1 As Object
   Public argument2 As Object
   Public argument3 As Object
   Public argument4 As Object
   Public argument5 As Object
End Sub

B4X:
Dim argc as ArgumentsContainer
argc.initialize
argc.argument1="one"
argc.argument2="two"
argc.argument3="three"
argc.argument4="four"
callsub2(Main,"function_name",argc)
note that any of the argments kan be an argumentscontainer as well....

the example of Penko is exactly what I mean.

A type is more appropriate than a class.

Type typArg(Arg1 As Object, Arg2 As Object, ...) (in Process_Globals)

Dim MyArgs As typArg
MyArgs.Initialize
MyArgs.Arg1 = ...
MyArgs.Arg2 = ...
CallSub2(Activity, "function_name", MyArgs)
 

Eduard

Active Member
Licensed User
Longtime User
Thank you for your example, but it is not what I need. I need a way to call a sub with three arguments, I want called "Activity_Touch".
use an extra sub
B4X:
Sub function_name(argc as argumentscontainer)
 activity_touch(argc.argument1,arc.argument2,argc.argument3,argc.argument4)
end sub
But I see your point...CallSub4 would benefit in your case
 
Last edited:

Dominex

Active Member
Licensed User
Longtime User
use an extra sub
B4X:
Sub function_name(argc as argumentscontainer)
 activity_touch(argc.argument1,arc.argument2,argc.argument3,argc.argument4)
end sub
But I see your point...CallSub4 would benefit in your case
I need CallSub4 why should I put it in a class / library and avoid adding specific code in Activity.

Thanks anyway for your ideas.
 
Top