Test 1
comp 125-609, Goldwasser
Tuesday, October 5, 1999

Name: _________________________

For each question, please Circle the one correct answer. If I can't tell which ONE is circled, it will unfortunately be marked wrong.
1. To write code which changes a property of an existing control, use the general syntax:
(A) Name of property = Appropriate value . Name of control
(B) Appropriate value = Name of property . Name of control
(C) Name of property . Name of control = Appropriate value
(D) Name of control . Name of property = Appropriate value

2. A form contains a picture box, a command button and the following code:
Private Sub Command1_Click()
  Dim Police As Integer
  Police = 911
  Picture1.Print Police
End Sub
When the user runs the program and presses the command button, what will be displayed?
(A) 911
(B) Police
(C) Integer
(D) Print

3. A form contains a picture box, a command button and the following code:
Private Sub Command1_Click()
  Dim X As Integer
  X = 12
  X = X + 5
  Picture1.Print "Value = "; X
End Sub
When the user clicks the command button, what is displayed?
(A) Value = 0
(B) Value = 5
(C) Value = 12
(D) Value = 17





4. A form contains two text boxes and the following code:
Private Sub Text1_GotFocus()
  Text1.Text = "Apples"
End Sub

Private Sub Text1_LostFocus()
  Text1.Text = "Oranges"
End Sub

Private Sub Text2_GotFocus()
  Text2.Text = "Pears"
End Sub

Private Sub Text2_LostFocus()
  Text2.Text = "Bananas"
End Sub
The user runs the program and clicks repeatedly on each text box in turn. The last one clicked is Text1. What will be displayed?
(A) in Text 1: Apples, in Text2: Bananas
(B) in Text 1: Oranges, in Text2: Bananas
(C) in Text 1: Apples, in Text2: Pears
(D) in Text 1: Oranges, in Text2: Pears

5. What does this do?
Last = Val(Text2.Text)
(A) Finds the last character typed into the text box.
(B) Interprets the contents of the text box as a numeric value.
(C) Changes the name property of the control from Text2 to Last.
(D) Changes the contents of the textbox to "Last".

6. A form contains a label, a command button and the following code:
Private Sub Command1_Click()
  Dim TheFirst As Integer
  Dim TheSecond As Integer
  TheFirst = 1999
  TheSecond = 53
  TheFirst = TheSecond
  TheSecond = TheFirst
  Label1.Caption = "TheFirst = " & TheFirst & ", The Second = " & The Second
End Sub
What is the caption of Label1 after the user clicks on Command1?
(A) TheFirst = 1999, TheSecond = 53
(B) TheFirst = 53, TheSecond = 1999
(C) TheFirst = 53, TheSecond = 53
(D) TheFirst = 1999, TheSecond = 1999

7. A form contains a label, a command button and the following code:
Private Sub Command1_Click()
  Dim X As Single
  Dim Y As Single
  X = 10
  Y = 4
  Label1.Caption = Str(3*Y+X/2)
End Sub
What is the caption of the label after the user clicks on the command button?
(A) 11
(B) 17
(C) 21
(D) 27

8. A form contains a picture box, a command button and the following code:
Private Sub Command1_Click()
  Dim foo As String, bar As String
  foo = "12"
  bar = "34"
  Picture1.Print foo & bar;
End Sub
When the user runs the program and presses the command button, what will be displayed?
(A) 46
(B) 1234
(C) foo & bar
(D) foobar






















9. This question concerns the scope of variables. A form contains two buttons, one picture box and the following code:
Dim X as Integer, Y As Integer, Z As Integer

Private Sub Command1_Click()
  Dim X as Integer
  X = 1
  Y = 2
End Sub

Private Sub Command2_Click()
  Dim Y as Integer
  X = 3
  Y = 6
End Sub

Private Sub Command3_Click()
  Dim Z as Integer
  Z = X + Y
  Picture1.Print Z
End Sub
The user clicks Command1, Command2 and Command3 in that order. What is displayed in the picture box?
(A) 3
(B) 5
(C) 7
(D) 9

10. The form contains a text box, a command button, a label and the following code:
Private Sub Command1_Click()
  Label1.Caption = "Q"
  If (Val(Text1.text) > 50) Then
    Label1.Caption = Label1.Caption & "R"
  End If
  Label1.Caption = Label1.Caption & "S"
End Sub
The user enters 25 into the textbox and then presses the command button. What is displayed in the label?
(A) Q
(B) QR
(C) QS
(D) QRS










11. Assume I want to simplify the following block of code:
  If (X < Y) Then
    If (Y < Z) Then
      text1.text = "Success"
    End If
  End If
Which of the following would behave equivalently?
(A)
  If (X < Y) And (Y < Z) Then
    text1.text = "Success"
  End If
(B)
  If (X < Y) Or (Y < Z) Then
    text1.text = "Success"
  End If
(C)
  If (X < Y) Not (Y < Z) Then
    text1.text = "Success"
  End If
(D)
  If (X < Y < Z) Then
    text1.text = "Success"
  End If

12. The form contains a label, a command button and the following code:
Private Sub Command1_Click()
  If ("apples" > "oranges") Then
    If ("bananas" = "pears") Then
      Label1.Caption = "A"
    Else
      Label1.Caption = "B"
    End If
  Else
    If ("bananas" <> "pears") 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
13. A form contains a picture box, a command button and the following code:
Private Sub Command1_Click()
  Dim n As integer
  For n = 15 to 25 Step 4
    Picture1.Print n;
  Next n
End Sub
When the user runs the program and presses the command button, what will be displayed?
(A)15 25 4
(B)15 19 23
(C)15 19 23 25
(D)15 19 23 27

14. Our goal is to create the following output in a picture box:
$
$$
$$$
$$$$
$$$$$
Which of the following pieces of code will acomplish this task?
(A)
  Dim X As Integer, Y As Integer
  For X = 1 to 5
    For Y = 1 to 5
      picture1.print "$";
    Next Y
    picture1.print ""
  Next X
(B)
  Dim X As Integer
  For X = 1 to 5
    picture1.print X * "$"
  Next X
(C)
  Dim X As Integer, Y As Integer
  For X = 1 to 5
    For Y = 1 to X
      picture1.print "$";
    Next Y
    picture1.print ""
  Next X
(D)
  Dim X As Integer
  For X = 1 to 5
    picture1.print "$"
  Next X

15. A form contains a picture box, a command button and the following code:
Private Sub Command1_Click()
  Dim n As integer
  n = 1
  Do While (n <= 4)
    n = n + 1
  Loop
  Picture1.Print n
End Sub
When the user runs the program and presses the command button, what will be displayed?
(A) 4
(B) 5
(C) 1 2 3 4
(D) 1 2 3 4 5

16. A form contains a picture box, a command button and the following code:
Private Sub Command1_Click()
  Dim n As integer
  n = 1
  Do 
    n = n + 1
  Loop Until (n >= 4)
  Picture1.Print n
End Sub
When the user runs the program and presses the command button, what will be displayed?
(A) 4
(B) 5
(C) 1 2 3 4
(D) 1 2 3 4 5

17. Assume that an array named Boo, consisting of 10 integers, has been dimensioned and initialized such that the following values exist:
Boo(1)=2
Boo(2)=3
Boo(3)=8
Boo(4)=7
Boo(5)=4
Boo(6)=9
Boo(7)=6
Boo(8)=10
Boo(9)=5
Boo(10)=1
What would be displayed by the line: Picture1.Print Boo(Boo(4))?
(A) 4
(B) 5
(C) 6
(D) 7





18. A programmer wishes to create an array of 40 strings to hold people's names. Which of the following is a legal declaration?
(A) Dim Name As String(1 to 40)
(B) Dim Name(1 to 40) As String
(C) Dim String As Name(1 to 40)
(D) Dim String(1 to 40) As Name

19. Assume the file "A:\junk.txt" appears as:
12
28
5, 17
35, 20
What is displayed when the user clicks on the command button with the following code?
Private Sub Command1_Click()
  Dim Apples, Oranges, Bananas, Pears as Integer
  Open "A:\junk.txt" For Input As #2
  Input #2, Apples, Oranges
  Input #2, Bananas, Pears
  Close #2
  Picture1.Print Bananas
End Sub
(A) 5
(B) 35
(C) 5, 17
(D) 35, 20

20. The user clicks on the command button with the following code:
Private Sub Command1_Click()
  Open "A:\results.txt" For Output As #1
  Write #1, "Hello", "Aloha"
  Close #1
End Sub
After doing so, if the user opens the file A:\results.txt using Notepad, what will he or she see?
(A)
  Hello
  Aloha
(B)
  "Hello"
  "Aloha"
(C)
  Hello, Aloha
(D)
  "Hello","Aloha"