SUB PROCEDURES

A simplified representation of the syntax for Sub procedures is:

Sub SubProcedureName ([argumentList])
[statements]
[Exit Sub]
[statements]
End Sub

where SubProcedureNme is the name you give to the Sub procedure, argumentList represents the argument list that is passed to the Sub procedure when it is called (multiple arguments are separated by commas), statements are a group of statements to be executed within the Sub procedure, and Exit Sub is a statement that provides an immediate exit from the procedure prior to its completion.

The Sub procedure is invoked by a Call statement, which has the syntax:

Call SubProcedureName ([argumentList])

The Call statement transfer program control to the Sub procedure. After the Sub procedure is executed, control returns to the line following the Call statement.

Here is a simple example that uses a Sub procedure to add two numbers:

Sub SimpleAddition()
assign values
a = 15
b = 28
compute the sum
Call Add(a, b, c)
MsgBox c
End Sub

Sub Add(a, b, c)
c = a + b
End Sub

We will now use a Sub procedure to solve a projectile problem in physics. The projectile is a football that has been kicked with some initial speed at a certain angle measured from the horizontal direction. Please read section 5.1.1 of our textbook for details concerning the underlying physics.

the Sub procedure will be called KickCalc.

In put data can be found in Sheet1 of the Excel worksheet KickCalc.xls.

Results for the hang time and the range will be computed using the Sub procedure KickCalc and will be written back on the same sheet.