Wyo Visual Basic Ch. 4 Practice Test                                                     Answers

True/False

  1. An If statement must have an ElseIf option. FALSE
  2. If a is True and b is False, then (a And b) is True. FALSE
  3. An even number is always evenly divisible by 2. TRUE
  4. The < symbol is a comparison operator.TRUE
  5. 20 mod 5 is 4. FALSE
  6. A Select Case statement can have 3 or more cases.TRUE
  7. It is possible to nest one If statement inside of another If statement.TRUE
  8. The ASCII value of a lowercase a is 13.FALSE
  9. The control expression ( intA > 3 Or intA < -9 ) is a compound Boolean expression.TRUE

Fill in the Blank - Write out the word True or False for the control expression problems.

  1. The operators And, Or, and Not are ______logical_______ operators.
  2. What is the ASCII value for an uppercase 'D'? 68
  3. If intA = 4 and intB = 8, simplify the control expression (intB > intA * 2) FALSE
  4. If intA = 4 and intB = 8, simplify the control expression (25 Mod (intB + intA)) 1

Write a Visual Basic statement that performs the following task.

  1. Write an If statement that displays the message "Hello" in the caption of lblMessage if the value of intGreeting is greater than 5.

    If (intGreeting > 5)
       lblMessage.Caption = "Hello"
    End If

  2. Write an If/ElseIf statement that displays the message "Gore" in the caption of lblVerdict if intGoreVotes is greater than intBushVotes. If intBushVotes is greater than intGoreVotes then the message "Bush won" should be displayed there. For this exercise, you can assume that intGoreVotes will not be equal to intBushVotes.

    If (intGoreVotes > intBushVotes) Then
       lblVerdict.Caption = "Gore"
    Else
       lblVerdict.Captoin = "Bush won"
    End If

  3. Write a Select Case statement that displays the message "A" in the caption of lblOutput if the value of intGrade is 10. If the value of intGrade is 9, then the displayed message should be "B". If the value of intGrade is 8, the message should be "C". Otherwise, the message should be "E".

    Select Case intGrade
    Case 10
       lblOutput.Caption = "A"
    Case 9
       lblOutput.Caption = "B"
    Case 8
       lblOutput.Caption = "C"
    Case Else
       lblOutput.Caption = "E"
    End Select

  4. Write a KeyPress event for a textbox named txtInput that displays a message box with the phrase "Good" if the user inputs a number that is greater than 10 followed by the Enter key.

    Private Sub txtInput_KeyPress(KeyAscii As Integer)

       If (KeyAscii = 13) Then
       
          If (Val(txtInput.Text) > 10) Then
           MsgBox "Good"
         End If

       End If

    End Sub