Extra Help

The new feature of the enhanced program are

Events

The first thing we need to consider is "What events do I need to program". The answer to this is "any events that change something in your program". Thankfully, we don't need to program this from scratch, we just need to find the required code segments and insert them into our own.

Step-by-step

  1. Insert the new controls

    Add a new command button and set its name to cmdFly and its caption to Fly. If you have a look at the printout, you should be able to see the description of this command button on the second page. It should look something like
    Begin VB.CommandButton cmdFly
    	Caption 		= "Fly"
    	....
    		
  2. Copy globals

    Go to the code editor. Use the object list and event list (see Exercise 3)to change to the general declarations section.

    Copy the following code (which is at the top of the printout) into the code editor
    'Global variables
    Dim flying As Boolean
    		
  3. Copy the code for "click fly button" event

    Go to the code editor, set the object list to cmdFly and the event list to Click. Now insert the following code, which can be found on page one of the printout, into this procedure.
    If flying Then
        flying = False
        cmdFly.Caption = "Fly"
    Else
        flying = True
        cmdFly.Caption = "Stop"
    End If
    		
  4. Copy the code for the mouse movement over the form background

    In the code editor, set the object list to Form (or whatever you named your calculate button) and your event list to MouseMove

    Now copy the following code for this procedure (which is on the first page of the printout)
    If flying Then
        frmRoomCalc.Top = frmRoomCalc.Top + 10
        frmRoomCalc.Left = frmRoomCalc.Left + 10
    End If
    		
  5. You should be done now, so run your project to test it out.

<- BACK TO EX 5


Matthew Roberts, Macquarie University 2002