Quiz 2
comp 125-609, Goldwasser
Tuesday, September 14, 1999

This quiz covers the following cumulative material: (alphabetical, with new topics shown in italics)
  • Reading: Ch 1, 2.1, 2.2, 2.3, 2.4, 3.1 and all class notes, labs and assignments to date
  • Controls: Command Button, Label, Picture Box, Text Box, Timer
  • Properties: Alignment, Caption, Font, ForeColor, Multiline, Name, Picture, Text
  • Events: Click, GotFocus, LostFocus
  • Methods: SetFocus
  • Data Types: Boolean, Integer, Single, String
  • Flow of Control: If Blocks, Select Case Blocks

  • Name: _________________________

    Please Circle the one correct answer. If I can't tell which ONE is circled, it will unfortunately be marked wrong.
    1. Consider the following code.
    Private Sub Command1_Click()
      Dim X As Single
      Dim Y As Single
      X = 5
      Y = X - 3
      X = X + 1
      Label1.Caption = Str(3*Y+X/2)
    End Sub
    
    What is the caption of Label1 after the user clicks on Command1?
    (A) 6
    (B) 7.5
    (C) 9
    (D) 12

    2. What is the value of X after the following two lines execute?
      Dim X As Integer
      X = 7/4
    (A) X=1
    (B) X=1.75
    (C) X=2
    (D) this code generates an error

    3. Which of the following is a false expression?
    (Note well: These are strings, not numbers)
    (A) ("1250" >= "125")
    (B) ("250" < "45")
    (C) ("70" = "70.0")
    (D) ("124" <> "0124")

    4. We want the display in Label5 to read:
    Fred earned $200,305.80 in 2 yrs.

    The following information was available on the form:
    The user typed his name in Text1 ("Fred")
    The user typed his salary in Text2 ("200305.80")
    The user typed the number of years at his present position in Text3 ("2")

    The code was very long, but some of the lines were:
    Dim Pay as Single, Work as Integer
    Pay = Val(Text2.Text)
    Work = Val(Text3.Text)

    (A) Label5.Caption = Text1.Text & " earned " & FormatCurrency(Pay) & " in " & Str(Work) & " yrs."
    (B) Label5.Caption = Text1.Text & " earned " & Pay & " in " & Work & " yrs."
    (C) Label5.Caption = Fred earned $200,305.80 in 2 yrs.
    (D) Label5.Caption = Text1.Text , FormatCurrency(Pay), Str(Work), " yrs."

    5. Consider the following code.
    Private Sub Command1_Click()
      Dim X As Integer
      Dim Y As Integer
      X = 4
      Y = 2
      If (X>Y) Then
        If (Y >= 4) Then
          Label1.Caption = "A"
        Else
          Label1.Caption = "B"
        End If
      Else
        If (X >= 4) Then
          Label1.Caption = "C"
        Else
          Label1.Caption = "D"
        End If
      End If
    End Sub
    
    What is the caption of Label1 after the user clicks on Command1?
    (A) A
    (B) B
    (C) C
    (D) D