Chapter 5 Homework Solutions:

Chapter 5-Menus, Sub Procedures and Sub Functions


1.           Explain the difference between a menu and a submenu.
The drop-down list of commands below a menu name (on the Menu bar) is called a menu. When a command on the menu has another list of commands that pops up, the new list is called a submenu.

2.           How can the user know if a menu command contains a submenu?
A filled triangle to the right of the command indicates that a menu command has a submenu.

3.           What is a separator bar and how is it created?
A separator bar is a line drawn across the entire menu to separate and group together commands according to their purpose.  While in the Menu Editor you can create a separator bar in a menu by typing a single hyphen (-) for the Caption and giving it a name. Even though you can never refer to the separator bar in code, and there is no Click event, you must still give it a unique name.

4.           Explain the purpose of the Name and Caption properties of menu items.
The Caption property of menu items holds the words you want to appear on the screen in the menu (just like the Caption property of a label or command button).  The Name property indicates the name of the menu control, similar to other controls.  The Name is required.

5.           What does the term common dialog box mean?
Common dialog boxes are a set of predefined standard dialog boxes for such tasks as specifying colors and fonts, printing, opening, and saving. The common dialog control, which is a custom control, allows a project to use the dialog boxes that are provided as part of the Windows environment.

6.           Name at least three types of common dialog boxes.
Common dialog boxes allow the user to select colors and fonts, and to perform duties pertaining to printing, opening, and saving files.

7.           Why would you need procedures that are not attached to an event?
Situations often occur in which more than one procedure performs the same operation.  This condition can occur when the user can select either a command button or a menu option to do the same thing.  Rather than retyping the code, you can write reusable code in a general procedure and call it from both event procedures.

8.           Code the necessary statements to produce a color dialog box and use it to change the background color of a form.
   Private Sub cmdColor_Click()
      ‘Display the Color Dialog Box

      ‘Assign dialog box color to the form
      frmMain.BackColor = dlgCommon.Color
   End Sub

9.           Explain the difference between a sub procedure and a function procedure.
A sub procedure is a procedure that performs actions.  A function procedure may perform an action, but it also returns a value (the return value) to the point from which it was called. The main difference between coding a function procedure and coding a sub procedure is that in a function you must set up the return value.

10.       What is meant by a return value?  How can it be used?
A function procedure performs an action and returns a value, called the return value, to the point from which it was called.  The return value is placed in a variable that is named by Visual Basic with the same name as the function name.  It is important to note that somewhere in the function, you must set the function name to a value.

11.       Explain the differences between ByRef and ByVal.  When would each be used?
When you pass a value to a procedure you may pass it ByVal or ByRef (for by value or by reference).  ByVal sends a copy of the argument’s value to the procedure.  You would use the ByVal when you do not want the procedure to alter the original value.  ByRef sends a reference indicating where the value is stored in memory.  You would use ByRef when you want the called procedure to actually change the argument's original value.  You can specify how you want to pass the argument by using the ByVal or ByRef keyword before the argument.  If you don't specify ByVal or ByRef, arguments are passed by reference.

12.    Give the steps required to convert a project into an EXE file.
To create an EXE file, select the Make ... command from the File menu.  The Make ... menu choice displays the name of the current project and the Make Project dialog box appears.  Next, choose the location and name for your EXE file.  You can also set properties for your project by clicking on the Options button.  In the Project Properties dialog box you can specify the version number, company name, and an icon for your file.