- Sub Procedures
- Creating Functions
- Using Optional Arguments
- Passing a Variable Number of Arguments
- Preserving Data Between Procedure Calls
- Understanding Scope
- Handling Runtime Errors
- Unstructured Exception Handling
- Structured Exception Handling
- Introducing Classes and Objects
- Summary
- Q&A
- Workshop
Workshop
This workshop tests whether you understand the concepts you saw today. It's a good idea to make sure you can answer these questions before pressing on to tomorrow's work.
Quiz
What's the difference between a function and a Sub procedure?
How can a Sub procedure pass data back to the calling code?
List three statements that will cause an immediate exit from a procedure.
What level of scope does a variable defined in a For loop have?
By default, what type of access do data members and methods have in classes?
Quiz Answers
A function can have a formal return value, whereas a Sub procedure cannot.
You can pass data back to the calling code if you pass a variable by reference. In that case, the code in the Sub procedure can assign a new value to that variable.
Return, Exit Sub/Function, and End Sub/Function.
Block-level scope.
Data members are private by default (that is, if declared with the Dim statement), and methods are public by default.
Exercises
Modify the Summer function discussed today to use the ParamArray keyword so that it will add as many integers as you pass to this function and return the total sum (not just the sum of two integers, as the version we've already seen today does).
As discussed in the text, add a new property, Color, to TheClass in the Classes example that will accept only the values "Red", "Green", and "Blue". If any other value is assigned to the Color property, store the word "Undefined" in that property.