LAB 7.1 - Jabberwocky

Goals:

    w Learn the graphical style for command buttons

    w Use a timer

    w Understand the MouseMove event

    w Learn how to use the Rnd function

    w Have some fun

 

__1. Begin a new project

          w Name your form frmGotcha

          w Name your project prjGotcha

          w Save both form and project

 

__2. Assemble an interesting set of objects

          w Place a command button, cmdClick, on the form.

     v Give it the caption CLICK ON ME!

     v Change its Style property to Graphical

     v Give it a bright Backcolor property

     v Make its Height 550 and its Width 900

          w Place a label, lblMissed, on the form.

     v Delete its caption

     v Do not change its Backcolor property

     v Give it the Arial font with a FontSize of 16

     v Make its Height 855 and its Width 3500

          w Place a timer, tmrGotMe, on the form.

     v Make its Enabled property False

     v Make its Interval property 4000

 

__3. Now for some interesting code

          w Give the Click event of cmdClick this code.

                        lblMissed.Caption = "FINALLY!!"

                        tmrGotme.Enabled = True

                        frmGotcha.Enabled = False

          w Give the Form_Load event this code.

                        frmGotcha.Left = 0

                        frmGotcha.Top = 0

                        frmGotcha.Width = 11950

                        frmGotcha.Height = 8500

          w Give the timer this code.

                        End


                w Give the Form_Click event this code.

                        Static round As Integer

                         Select Case round

                          Case 0: lblMissed.Caption = "You Missed ME!!"

                          Case 1: lblMissed.Caption = "Try Again!!"

                          Case 2: lblMissed.Caption = "Slow Poke!!"

                          Case 3: lblMissed.Caption = "Whew, That was close! NOT!"

                          Case 4: lblMissed.Caption = "Kinda pokey, aintcha?!"

                         End Select

                         round = (round + 1) Mod 5

          w Give the MouseMove event of cmdClick this code.

                        cmdClick.Left = Rnd * (frmGotcha.Width - 900)

                        cmdClick.Top = Rnd * (frmGotcha.Height - 550 - 120)

 

__4. Study the program. 

          w Can you predict what is going to happen?

          w Run it.

          w Can you describe what is happening and why?

 

__5. Study the program again.

          w Get into Design mode.

          w Learn about the MouseMove event

     v Click on cmdClick to make it the active object

     v Press F1 to bring up context sensitive help

     v Click on Events in the description of Command Button

                     Control that comes up

     v What do you learn from the Remarks section of the entry?

                      How does that explain what happened when you ran the

                      program?

          w Learn about the Rnd function

     v Click on Rnd in the code to highlight it

     v Press F1 again

     v What kind of value does the Rnd function return?

          w Study the code

     v Why is the value returned by Rnd multiplied by the form’s

                     dimensions?

     v Why are 900 and 550 subtracted prior to the multiplication?

     v Why is an additional 120 subtracted from the height?

     v Why is the variable round declared to be Static?  Why is it not

                      initialized?

     v What is the purpose of the line below?

                                     round = (round + 1) Mod 5

     v What is the purpose of the timer?

 

__6. Improve on the program

          w Come up with your own messages for Form_Click

          w Can you think of a way to present these messages at random,

              instead of simply cycling them in the same order?

          w Do it!

 

__7. Can you think of a way to “catch” the command button?

 

__8. Congratulations!  You have finished another lab.  Did you find it interesting?