' Ch. 8 Demo Program #1 ' Mr. Minich ' Purpose - to illustrate the use of general procedures, ' Select Case structures, menu control arrays, ' With structures.
Option Explicit Dim mUserScore As Integer ' user's total game score (a module-level variable) Private Sub Form_Load() MsgBox "Welcome to Mr. Minich's Jeopardy!!" Call mnuGameNewGame_Click End Sub Private Sub mnuGameNewGame_Click() Dim x As Integer ' loop variable mUserScore = 0 ' resetting score to zero lblPoints = "" ' clearing label with user's score For x = 0 To 2 ' unchecking & enabling submenu items With mnuSportsPoints(x) .Checked = False .Enabled = True End With Next x
End Sub Private Sub mnuSportsPoints_Click(Index As Integer) ' This event procedure contains the questions and answers.
' Procedures called: AskAndCheckQuestion, Disable Dim Question As String ' sports question Dim Answer As String ' correct answer to question Select Case Index Case 0 Question = "(T/F) The Dolphins are the best NFL football team." Answer = "T" Call AskAndCheckQuestion(Question, Answer, 10) ' asks question and checks answer Call Disable(Index) ' disables the point value on the submenu Case 1 Question = "In what city, do the Dolphins play football?" Answer = "Miami" Call AskAndCheckQuestion(Question, Answer, 20) ' asks question and checks answer Call Disable(Index) ' disables the point value on the submenu Case 2 Question = "(T/F) The Dolphins are going to win the Super Bowl next year." Answer = "T" Call AskAndCheckQuestion(Question, Answer, 30) ' asks question and checks answer Call Disable(Index) ' disables the point value on the submenu Case Else MsgBox "An error occurred in the Sports submenu." End Select End Sub Private Sub mnuGameExit_Click() ' This event procedure exits the game when the user clicks the Exit menu command. End ' exiting the game End Sub Private Sub AskAndCheckQuestion(QuestionToAsk As String, CorrectAnswer As String, NumPoints As Integer) ' This general procedure asks the user a question and checks the answer. ' If the answer is correct the correct number of points is ' added to the player's overall score. Otherwise, the number ' of points is deducted from his or her score. ' Called by: mnuSportsPoints_Click If CorrectAnswer = InputBox(QuestionToAsk) Then mUserScore = mUserScore + NumPoints ' adding to user's score Else mUserScore = mUserScore - NumPoints ' subtracting from user's score End If lblPoints = mUserScore End Sub Private Sub Disable(IndexValue As Integer) ' This general procedure checks and disables the correctly answered question ' on the submenu. ' Called by: mnuSportsPoints_Click With mnuSportsPoints(IndexValue) ' checking & disabling .Checked = True .Enabled = False End With End Sub