7.7. Notes on Declaring and Using MethodsThere are three ways to call a method:
Note that a Shared method can call only other Shared methods of the same class directly (i.e., using the method name by itself) and can manipulate only Shared members in the same class directly. To access the class's non-Shared members, a Shared method must use a reference to an object of the class. Recall that Shared methods relate to the class, whereas non-Shared methods are associated with a specific instance (object) of the class and may manipulate the instance variables of that object. Many objects of a class, each with its own copies of the instance variables, may exist at the same time. Suppose a Shared method were to invoke a non-Shared method directly. How would the method know which object's instance variables to manipulate? What would happen if no objects of the class existed at the time the non-Shared method was invoked? Thus, a Shared method cannot access non-Shared members of the same class directly. Control can be returned to the statement that calls a method by using the Return statement or by reaching the end of the method (End Sub or End Function). If the method does not return a result but uses a Return statement to return control to the calling method, the Return statement cannot include an expression. If the method does return a result, the statement
evaluates the expression, then returns the result to the caller. Common Programming Error 7.4
Common Programming Error 7.5
Common Programming Error 7.6
Common Programming Error 7.7
|