Android Question CallSub question

GaNdAlF89

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

Example:
B4X:
Sub Activity_Resume
  CallSub(Null,"RefreshData")
End Sub

'or

Sub Activity_Resume
  RefreshData
End Sub
 

Troberg

Well-Known Member
Licensed User
Longtime 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
Top