Subroutines

A procedure is a block of code that performs a specific task. As programs become more and more complex, keeping your code organized can become a headache. Dividing your code into smaller chunks of code(procedures) makes it easier to manage. In addition, redunent and repetative tasks can be handled easily using Sub Procedures.

Lets take a look at an example program

This program simply supplies directions to get to various cities from Nanaimo. I am going to save typing because

To go to Campbell River, I go to Parksville, then Courtney, then Campbell River

To go to Mt Washington, I go to Parksville, the Courtney, then up the mountain

To go to Parksville, I go to Parksville.

I don't want to write out of directions to Parksville 3 times. So I will use a procedure once and call it 3 times.


Check out the code

Option 1 takes us to Parksville

Option 2 takes us to Mt Washington but I reuse the GotoParksville Procedure. (Pretty smart eh?)


So what do these new subroutines look like and how do I create them

Well here they are

To create them simple choose Tools Add procedure to bring up the following window

Type in the name and choose sub


At this point check out the first assignment.