Home > Articles > Programming > Visual Basic

  • Print
  • + Share This
This chapter is from the book

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

  1. What's the difference between a function and a Sub procedure?

  2. How can a Sub procedure pass data back to the calling code?

  3. List three statements that will cause an immediate exit from a procedure.

  4. What level of scope does a variable defined in a For loop have?

  5. By default, what type of access do data members and methods have in classes?

Quiz Answers

  1. A function can have a formal return value, whereas a Sub procedure cannot.

  2. 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.

  3. Return, Exit Sub/Function, and End Sub/Function.

  4. Block-level scope.

  5. Data members are private by default (that is, if declared with the Dim statement), and methods are public by default.

Exercises

  1. 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).

  2. 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.

  • + Share This
  • 🔖 Save To Your Account