Lab 7
comp 125-609, Goldwasser
Tuesday, October 12, 1999

Purpose: Using general procedures and functions
Please start by saving the following two files to disk (either a floppy or D:\userdata)
  • http://www.cs.luc.edu/~mhg/comp125/labs/lab7.vbp
  • http://www.cs.luc.edu/~mhg/comp125/labs/lab7.frm
  • You will be modifying this program by adding some new procedures.

    NOTE: Do NOT modify the code in the Click routines and do not access the textbox or picturebox controls in any of the code which you write.


    To get some practice using procedures and functions, we are going to learn to write what is called a "wrapper function".

    While writting programs, you will often run across a situation in which you want a function which is almost identical to one which already exists, but with a few minor changes. Possibly you want the parameter list to be different, or possibly you want the behavior to be modified slightly.

    Rather than re-writing a new function completely from scratch, you can often get away pretending to write a new function, but having your function call the already existing function when you need it. By doing it this way however, you have the opportunity to add a few of your own lines of code before or after the existing function gets called.


    Let's see this in action.

    Visual Basic has a built in function called InputBox which brings a pop-up window onto the screen asking the user to enter some text (see page 100). To call this function, you might use the syntax answer = InputBox(prompt,title) where prompt and title are String variables or constants. This function returns as its result, the string which the user entered

    Your goal for this lab is to successfully acomplish three tasks, modifying the project which you have downloaded:

  • Write a wrapper function named Wrapper which behaves exactly like the function InputBox. That is, I want a line of code such as:
       answer = Wrapper(prompt,title)
    
    to behave exactly as the line answer = InputBox(prompt,title) would behave.

    To do this, you simply need to know how to write the function definition correctly (i.e., specifying its parameters, and its return values). The body of this function can simply be a single line which calls the original InputBox function to do the work.

  • Once this is done, modify your Wrapper function so that it behaves slightly differently than the original. Normally, when InputBox is called, the Form window is still visible in the background. I want your version of Wrapper to make the Form window invisible while the input box is on the screen. To do this simply set Form1.Visible = false before calling InputBox and then Form1.Visible = true after the call to InputBox.

  • Write a new procedure named SuperWrapper which is going to act as a "wrapper function" for your function Wrapper. However, SuperWrapper is not going to be a true function, rather it is going to be defined as a sub procedure, and we will use an extra parameter in order to pass the user's entry back to the caller. The calling syntax for your function will be: Call SuperWrapper(result, prompt, title) where all three parameters are String variables. Your procedure should behave just like Wrapper behaves, however it should set the value of result to be the text which the user enters.

  • This lab is due before leaving class today. When you have completed the program you should do the following:
  • (1) Print out your project as follows. Click "File". Click "Print". In the Range box, select "Current project". In the Print What box, click only on "Code".
  • (2) Please call me over to your computer to run your program and to turn in your printout.