Android Question CallSub question

Discussion in 'Android Questions' started by GaNdAlF89, May 11, 2015.

  1. GaNdAlF89

    GaNdAlF89 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
  2. Erel

    Erel Administrator Staff Member Licensed User

    There is no practical difference. You shouldn't use CallSub in this case (CallSubDelayed can be useful).
    GaNdAlF89 likes this.
  3. Troberg

    Troberg 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.
    GaNdAlF89, Erel and thedesolatesoul like this.
  4. GaNdAlF89

    GaNdAlF89 Active Member Licensed User

    Thank you both!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice