Programming in Any Language

Introduction to Methods

Click for larger image.

Methods! We used to call these things subroutines back in the days of BASIC and COBOL. Algorithms or routines that perform a task is what they actually are. Each one can be called many times from many different locations. Basically, they are buttons without the button. PDF: Code


The VOID Method

Click for larger image.

The VOID method returns no values. That’s why the data type is VOID. It is a snippet of code or an algorithm that performs a specific task every time you call it. Think of it as a subroutine. It does something. PDF: Code


Passing Arguments to Methods

Click for larger image.

A better and safer way to program is to create variables in your methods and events. If you need to share them with another routine, you can pass the value (not the variable) to the new method. It can do what it wants with that data, but it will never damage what you originally have stored in that variable. PDF: Code


Value-Returning Methods

Click for larger image.

Value-Returning methods allow us to return a value to a variable in the calling modules. We will bypass global variables entirely. We will create a variable and place an equal sign after the variable. That equal sign is then followed by a call to a method. PDF: Code


Passing Arguments by Reference

Click for larger image.

By using a method that is given access to the memory location of our variable rather than the value of the variable, our method could make the change to the value right in the calling module. Typically, these are VOID methods. They don’t need to return any values because they are messing with the actual original value. PDF: Code