Android Question CallSub question


Active Member
Licensed User
Hi, what is the difference between to call a sub through its name or with CallSub, in the same module?

Sub Activity_Resume
End Sub


Sub Activity_Resume
End Sub


Well-Known Member
Licensed User
CallSub is useful if you are calling a method on an object which you do not know the type of, but you know that it has that method.

Stupid example, but the best I can think of at the moment:

Class Animal_Fish has the methods Swim and Eat.
Class Animal_Bird has the methods Fly and Eat.
Class Animal_Dachshound has the methods Bark and Eat.
Class Animal_Cow has the methods Poop and Eat.

Now, you have animals of all types in an list. You want to run though the list and feed them all. You can't simply dim CurrentAnimal as object and call CurrentAnimal.Eat, as you don't know the type. However, you can dim it as object and use CallSub(CurrentAnimal, "Eat").

That's useful.
Upvote 0