1.     What will be the contents of the variable x after the following statement is executed?

x = Sqr((9 + 7) / (4 * 2) + 2)

(A)      1

(B)       2

(C)       3

(D)      4

(E)       None of the above

 

2.     What statement should be used to generate random numbers from the set 2, 3, 4, 5, 6, 7?

(A)      Rnd * 7

(B)       Int(Rnd * 7) + 1

(C)       Int(Rnd * 7) + 2

(D)      Int(Rnd * 6) + 2

 

3.      Which of the following expressions will yield the string "John Doe", where nom1 = "John Blake" and nom2 = "Janet Doe"?

         (A)    Mid$(nom1, 1, 4) & Mid$(nom2, 7, 10)

         (B)    Left$(nom1, 4) & Right$(nom2, 3)

         (C)    Left$(nom1, 5) & Right$(nom2, 3)

         (D)    None of the above.

 

4.     What will be the output of the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim word As String

  word = "progression"

  Call Strange(word)

End Sub

Private Sub Strange(var As String)

  picBox.Print Mid$(var, Int(Len(var) / 2), 1)

End Sub

(A)      progr

(B)       r

(C)       e

(D)      progre

(E)       None of the above

 

5.     Suppose the variable myName is declared in a Dim statement in two different Sub procedures. Which statement is true?

(A)      The program will malfunction when it is executed.

(B)       When the value of myName is changed in one Sub procedure, it will also be changed in the other Sub procedure.

(C)       Visual Basic's smart editor will alert you that this is an error before the program is executed.

(D)      The two variables will be local to their respective Sub procedure.

 

6.     What will be the output of the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim var1 As Integer, var2 As Integer, var3 As Integer, num As Integer

  var1 = 2

  var2 = 4

  var3 = 6

  Call Add(num)

  picBox.Cls

  picBox.Print num

End Sub             ‘continued on next page

Private Sub Add(num As Integer)

  Dim var1 As Integer, var2 As Integer, var3 As Integer

  num = var1 + var2 + var3

End Sub

(A)      0

(B)       12

(C)       6

(D)      None of the above

 

7.     The arguments appearing in a call statement must match the parameters in the appropriate Sub or Function statement in all but one of the following ways. Which one?

(A)      Number of arguments

(B)       Names of arguments

(C)       Data type of arguments

(D)      Order of arguments

 

8.     Stepwise refinement refers to

(A)      the process whereby a malfunctioning program is fixed by correcting one "bug" at a time.

(B)       any procedure that calls another procedure (and so on) to accomplish a task.

(C)       breaking a large problem into smaller problems.

(D)      the belief that increasing the number of people working on a project decreases
 the time it will take to complete the project.

 

9.    Consider the following two sets of instructions.

1.  If a = 1 And b = 1 Then               2.         If a = 1 Then

           picBox.Print "Hello"              If b = 1 Then

   End If                                    picBox.Print "Hello"

                                         End If

                                     End If

        Which one of the following statements is true?

(A)      1 and 2 will produce different output.

(B)       2 is not a valid set of Visual Basic instructions.

(C)       1 is preferred to 2 because 1 is easier to read.

(D)      The condition statement in 1 is not valid.

 

10.  What will be displayed by the following program when the command button is clicked?

 

Private Sub cmdButton_Click()

  Dim a As Single, b As Single, c As Single, x As Single

  a = 5

  b = 3

  c = 6 

  If a > c Then

      x = 1

  Else

      If b > c Then

          x = 2

      Else

          x = 3

          picBox.Print x

      End If

  End If

End Sub                   ‘continued on next page

(A)      1

(B)       2

(C)       3

(D)      None of the above.

 

11.  Consider the following program.

Private Sub cmdButton_Click()

  Dim x As Single, y As Single, z As Single

  Open "DATA.TXT" For Input As #1

  Input #1, x, y, z

  If ((x > y) Or (x > z)) And (z >= 100) Then

      picBox.Print "Hello, ";

  Else

      picBox.Print "Good-bye, ";

  End If

  Close #1

  picBox.Print "Larry."

End Sub

        Which of the following sets of data in the file DATA.TXT will produce the output "Hello, Larry."

(A)      2, 3, 101

(B)       3, 2, 100

(C)       2, 3, 100

(D)      3, 2, 4

 

12.  What will be the output of the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim word1 As String, word2 As String, newword As String

  word1 = "shower"

  word2 = "about"

  newword = Left$(word1, 4) & Left$(word2, 3)

  If InStr(newword, "how") = 0 Then

      picBox.Print "The new word was not found."

  Else

      picBox.Print "Found it."

  End If

End Sub

(A)      The new word was not found.

(B)       Found it.

(C)       Syntax error

(D)      No output

 

13.  What will be the output of the following program when the command button is clicked?

 

Private Sub cmdDisplay_Click()

  Dim num As Integer

  num = 10

  Call DisplayMult(num)

  num = 5

  Call DisplayMult(num)

  num = 2

  Call DisplayMult(num)

End Sub

 

Private Sub DisplayMult(num As Integer)

  If num <= 3 Then

      picOutput.Print 3 * num;

  Else

      If num > 7 Then

        picOutput.Print 7 * num;

      End If

  End If

End Sub

(A)      70  14

(B)       30  6  14

(C)       70  6

(D)      No output

 

14.  What will be the output of the following lines of code?

phrase = "A penny saved is worth nothing."

If InStr(phrase, "pen") <> 0 Then

    picBox.Print InStr(phrase, "pen")

Else

    picBox.Print 0

End If

(A)      pen

(B)       3

(C)       0

(D)      A penny saved is worth nothing.

 

15.  Write an If...ElseIf statement to determine if character string Str1 is greater than, less than or equal to character string Str2. Print a message indicating which condition is true for each situation.

 

16.  What will be the output of the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim a As String, b As String, c As String, acronym As String

  a = "federal"

  b = "aviation"

  c = "administration"

  acronym = Left(a, 1) & Left(b, 1) & Left(c, 1)

  Select Case acronym

    Case "FAA"

      picBox.Print "Federal Aviation Administration"

    Case "DEA"

      picBox.Print "Drug Enforcement Agency"

    Case Else

      picBox.Print "Unknown acronym. Sorry."

  End Select

End Sub

(A)      Federal Aviation Administration

(B)       Drug Enforcement Agency

(C)       Syntax error

(D)      Unknown acronym. Sorry.

 

17.  What will be the output of the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim num as Single

  num = 10

  Do While num > 1

    picBox.Print num;

    num = num - 3

  Loop

End Sub

(A)      10   7   4

(B)       10   7   4   1  

(C)       10   7   4   1   -2

(D)      No output

 

18.  In analyzing the solution to a program, you conclude that you want to construct a loop so control leaves the loop either when a < 12 or when b = 16. Using a Do loop, the test condition should be

(A)      Do While (a > 12) Or (b <>16)

(B)       Do While (a >= 12) Or (b <> 16)

(C)       Do While (a < 12) Or (b <> 16)

(D)      Do While (a >= 12) And (b <> 16)

(E)       Do While (a < 12) And (b = 16)

 

19.  Using a Do While Loop, write the necessary code to calculate the product of:

5 x 10 x 15 x 20 x ...x 70.

 

20.   What will be displayed by the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim letter As String, s As String

  Open "DATA.TXT" For Input As #1

  Input #1, letter

  s = ""

  Do While letter <> "q"

    s = letter + s

    Input #1, letter

  Loop

  picBox.Print s

End Sub

        Contents of DATA.TXT: n, o, p, q, r, s, t

(A)      rst

(B)       pon

(C)       nop

(D)      qpon

(E)       None of the above

 

21.   What is wrong with the following simple password program where today's password is "intrepid?"

Private Sub cmdButton_Click()

  Dim passwd As String

  passwd = InputBox("Enter today's password:")

  Do

    picBox.Print "Incorrect"

    passwd = InputBox("Enter today's password:")

  Loop Until passwd = "intrepid"

  picBox.Print "Password Correct.  You may continue."

End Sub

(A)      There is no way to re-enter a failed password.

(B)       The Loop Until condition should be passwd <> "intrepid".

(C)       It will always print "Incorrect."

(D)      Nothing

 

22.  What will be displayed by the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim x As Single, y As Single, z As Single

  Open "DATA.TXT" For Input As #1

  y = 0

  Input #1, x

  Do While x < 5

    If x = 4 Then

        Close #1

        Open "DATA.TXT" For Input As #1

    End If

    z = x + y

    Input #1, x, y

  Loop

  picBox.Print z

  Close #1

End Sub

        Contents of DATA.TXT: 3, 4, 6, 8, 1, 2, 5, 9, 3

(A)      9

(B)       14

(C)       10

(D)      7

(E)       None of the above

 

23.  What will be the output of the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim vowel As String

  Open "DATA.TXT" For Input As #1

  Do While EOF(1)

    Input #1, vowel

    picBox.Print vowel;

  Loop

  Close #1

  picBox.Print ", and sometimes y"

End Sub

        Contents of DATA.TXT: a, e, i, o, u

(A)      , and sometimes y

(B)       a, and sometimes y

(C)       aeiou, and sometimes y

(D)      aeiou

 

24.  What will be displayed by the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim j As Single, k As Single

  Open "DATA.TXT" For Input As #1

  Input #1, j

  Do While j < 5

    Input #1, k

    If k < j Then

        Input #1, j

    End If

  Loop

  picBox.Print k

End Sub

        Contents of DATA.TXT: 3, 4, 1, 5, 2, 6

(A)      1

(B)       2

(C)       3

(D)      4

(E)       5

 

25.  What will be displayed in the picture box by the following code when the command button is clicked?

 

Private Sub cmdButton_Click()

  Dim num As Integer

  num = 7

  Do

    num = num + 1

    picBox.Print num;

  Loop Until num > 6

  picBox.Print num

End Sub

 

(A)  7

(B)  8

(C)  7  8

(D)  8  8

        

26.  When the number of repetitions needed for a set of instructions is known before they are executed in a program, the best repetition structure to use is a(n)

(A)      Do While...Loop structure.

(B)   Do...Loop Until structure.

(C)       For...Next loop.

(D)      If block with a GoTo statement.

 

27.  What is wrong with the following set of instructions?

For index1 = 10 To 1 Step -1

  For index2 = 1 To 1

    picBox.Print "Hello"

  Next index1

Next index2

(A)      The loops are not nested properly.

(B)       One cannot have a negative Step value.

(C)       Indices in For...Next loops must be of the form: i, j, etc.

(D)      "index2 = 1 to 1" is not a valid statement in Visual Basic.

 

28.  When the odd numbers are added successively, any finite sum will be a perfect square (e.g., 1 + 3 + 5 = 9 and 9 = 3^2). What change must be made in the following program to correctly demonstrate this fact for the first few odd numbers?

Private Sub cmdButton_Click()

  Dim oddnum As Single, sum As Single, i As Integer, j As Integer

  sum = 0

  For i = 1 To 9 Step 2         'Generate first few odd numbers

    oddnum = i

    For j = 1 To oddnum Step 2       'Add odd numbers

      sum = sum + j

    Next j

    picBox.Print sum; "is a perfect square."

  Next i

End Sub

(A)      Change the Step size to 1 in the first For statement.

(B)       Move "oddnum = i" inside the second For loop.

(C)       Reset "sum" to zero immediately before "Next i."

(D)      Reset "sum" to zero immediately before "Next j."

 

29.  Given the following partial program, how many times will the statement picBox.Print j, k, m be executed?

For j = 1 To 4

  For k = 1 To 3

    For m = 2 To 10 Step 3

      picBox.Print j, k, m

    Next m

  Next k

Next j

(A)      24

(B)       60

(C)       36

(D)      10

(E)       None of the above

 

30.  Which of the following program segments will sum all the numbers read in? Assume the data file has been open for input as #1.

(A)      For k = 1 To 8

       Input #1, s

       s = s + k

     Next k

(B)       For k = 1 To 8

       Input #1, a

       s = s + 1

     Next k

(C)       For k = 1 To 8

       Input #1, a

       a = a + s

     Next k

(D)      For k = 1 To 8

       Input #1, s

       s = k + a

     Next k

(E)       None of the above

 

31.  What will be displayed by the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim x As String, y As String, k As Integer

  Open "DATA.TXT" For Input As #1

  Input #1, x

  For k = 1 To 4

    Input #1, y

    If x > y Then

        x = y

    End If

  Next k

  Close #1

  picBox.Print x

End Sub

        Contents of DATA.TXT: "CAROL", "DAVE", "ABE", "EMILY", "BOB"

(A)      CAROL

(B)       ABE

(C)       EMILY

(D)      DAVE

(E)       BOB

 

32.  What will be displayed by the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim s As Single, k As Single

  s = 0

  For k = 1 To 5

    If k / 2 = Int(k / 2) Then

        s = s + k

    End If

  Next k

picBox.Print s

End Sub

(A)      12

(B)         9

(C)       15

(D)        6

(E)       None of the above

 

33.  What should be the output of the following program segment?

    For k = 1 To 1000

       x = Rnd

       y = Rnd

       If x > y Then

           count = count + 1

       End If

     Next k

     picBox.Print count

(A)      approximately 500

(B)       approximately 250

(C)       0

(D)      1000

(E)       It is impossible to know in advance

 

34.  After the following Dim statement, how many subscripted variables called myvar(i) will be available?

Dim myvar(3 To 8) As Single

(A)      5

(B)       6

(C)       7

(D)      8

(E)       9

 

35.  Which of the following cannot be used to assign values to a subscripted variable?

(A)      InputBox

(B)       Print

(C)       Assignment statement

(D)      Input#

(E)       All of the above

 

36.  Which of the following is NOT a valid Dim statement?

(A)      Dim myArray(0 To 1) As String

(B)       Dim bigarray(100) As Single

(C)       Dim numbers(4 To 1) As Single

(D)      Dim values(-3 To 3) As Integer

 

37.  What is the output of the following program when the command button is clicked?

Private Sub cmdButton_Click()

  Dim i As Integer, nom(1 To 5) As String

  Open "DATA.TXT" For Input As #1

  For i = 1 To 5     

    Input #1, nom(i)   

  Next i   

  Close #1   

  picBox.Cls   

  For i = 5 To 1 Step -2     

     picBox.Print nom(i); " ";   

  Next i 

End Sub

        Contents of DATA.TXT: "Bach", "Borodin", "Brahms", "Beethoven", "Britain"

(A)      Bach Brahms Britain

(B)       Britain Beethoven Brahms Borodin Bach

(C)       Bach Borodin Brahms Beethoven Britain

(D)      Britain Brahms Bach

(E)       None of the above

 

38.  What is the output of the following program segment?

picBox.Cls 

Dim num(0 To 9) As Integer, i As Integer, k As Integer, total As Integer

For i = 0 To 9   

  num(i) = i 

Next i 

total = 0 

For k = 0 To 4   

  total = total + 10 ^ num(k) 

Next k 

picBox.Print total

(A)      10000

(B)       11111

(C)       1111

(D)      0

(E)       1000

 

39.  What will be the value of phrase(2) after the following code is executed?

Dim sentence As String, place As Integer, i As Integer

Dim char As String. phrase(1 To 10) As String

sentence = "Every path hath a puddle."

place = 1

i = 1

char = Mid$(sentence, place, 1)

Do

  If char = " " Then

      phrase(i) = Mid$(sentence, 1, place - 1)

      i = i + 1

  End If

  place = place + 1

  char = Mid$(sentence, place, 1)

Loop Until char = "."

(A)      Every

(B)       Every path

(C)       Every path hath

(D)      Every path hath a

(E)       Every path hath a puddle

 

40.  What will be displayed when the following program segment is executed?

Dim a(4) As Single, k As Integer

Open "DATA.TXT" For Input As #1

For k = 0 To 4

  Input #1, a(k)

Next k

Close #1

picBox.Cls

picBox.Print a(3)

        Contents of DATA.TXT: 3, 2, 5, 1, 4

(A)      1

(B)       2

(C)       3

(D)      4

(E)       5

 

41.  What is the output of the following program segment?

Dim numbers(1 To 4) As Single, h As Single, i As Integer, k As Integer

h = 0

Open "DATA.TXT" For Input As #1

For i = 1 To 4

  Input #1, numbers(i)

Next i

Close #1

For k = 1 to 4

  h = h + numbers(k)

Next k

picBox.Cls

picBox.Print h

        Contents of DATA.TXT: 2, 4, 2, 3

(A)      11

(B)       2

(C)       7

(D)      4

(E)       None of the above

 

42.  What is the output of the following program segment?

Dim myArray(1 To 5) As Single, i As Integer, num As Integer, k As Integer

Open "DATA.TXT" For Input As #1

For i = 1 To 5

  Input #1, myArray(i)

Next i

Input #1, num

Close #1

k = 1

Do While (num > myArray(k)) And (k <= 5)

  k = k + 1

Loop

picBox.Cls

picBox.Print k

        Contents of DATA.TXT: 2, 4, 6, 8, 10, 3

(A)      1

(B)       2

(C)       3

(D)      4

(E)       None of the above

 

43.  What is the output of the following program segment?

Dim a(1 To 20) As Single, b(1 To 20) As Single, c As Single, k As Integer

c = 0

Open "DATA1.TXT" For Input As #1

For k = 1 To 20

  Input #1, a(k)

Next k

Close #1

Open "DATA2.TXT" For Input As #1

For k = 1 To 20

  Input #1, b(k)

Next k

Close #1

For k = 1 To 20

  If a(k) = b(k) Then

       c = c + 1

  End If

Next k

picBox.Print c

        Contents of DATA1.TXT: 3,2,5,1,7,8,3,5,6,2,3,6,1,6,5,5,7,2,5,3 

        Contents of DATA2.TXT: 5,3,3,4,8,2,3,5,9,5,3,7,3,7,6,3,2,1,3,4

(A)      2

(B)       3

(C)       4

(D)      5

(E)       6

 

44.  What is the output of the following program segment?

Dim antonym(0 To 8) As String, i As Integer

Open "DATA.TXT" For Input As #1

For i = 0 To 6 Step 2

  Input #1, antonym(i), antonym(i + 1)

Next i

Close #1

picBox.Cls

picBox.Print antonym(3)

       

   ‘Data file on next page
Contents of DATA.TXT:       "big", "small"

                                                "black", "white"

                                                "old", "young"

                                                "fast", "slow"

                                                "tall", "short"

                                                "hard", "soft"

(A)      black

(B)       white

(C)       small

(D)      Subscript out of range

 

45.  What is the output of the following program segment?

Dim phonedir(1 To 50) As String, i As Integer

Open "DATA.TXT" For Input As #1

For i = 1 To 10 Step 3

  Input #1, phonedir(i), phonedir(i + 1), phonedir(i + 2) 

Next i

Close #1

picBox.Cls

i = 2

Do While phonedir(i) <> ""

  picBox.Print phonedir(i); " ";

  i = i + 3

Loop

        Contents of DATA.TXT:   "Fischer", "John", "797-3456"

                                                "Robinson", "Max", "535-8657"

                                                "Stanberg", "Jennifer", "544-9080"

                                                "Thompson", "Meg", "436-2345"

(A)      Fischer Robinson Stanberg Thompson 

(B)       John Max Jennifer Meg

(C)       797-3456 535-8657 544-9080 436-2345

(D)      No output

 

46.  Declare an array and write a code segment that will (1) read 20 integer test scores into the array and (2) count the number of scores greater than or equal to 70.

 

47.  In Visual Basic, the Index property of a control is used with

(A)      any array.

(B)       control arrays.

(C)       tab order.

(D)      position on the form.

 


48.  Given the following array, what value will be assigned to num?

 

 

 

 

Myarray()

 

 

 

num = myArray(4,5)

 

1

2

3

4

5

 

1

0

1

2

3

4

 

2

5

6

7

8

9

 

3

10

11

12

13

14

 

4

15

16

17

18

19

 

5

20

21

22

23

24

(A)      19

(B)       4

(C)       24

(D)      0

(E)       None of the above

 

49.  Assume the array b() has been filled as shown. What is the output of the following program segment?

 

                                                        b()

                                               1     2     3     4

s = 0                                       |-------------------

For k = 1 To 3                           1  |  2     3     4     5

  s = s + b(k, k + 1)                       |

Next k                                   2  |  6     5      4    3

picBox.Print s                              |

                                         3  |  2     3      4    5

                                            |

                                         4  |  6     5     4     3

(A)      64

(B)       12

(C)       13

(D)      25

(E)       None of the above

 

50.  Assume the array num() has been filled as shown. What is the output of the following program segment?

For j = 1 To 3                                       num()

   For m = 1 To 2                                 1     2     3

     If num(j, m) > num(j, m + 1) Then           -----------------

         temp = num(j, m)                     1|  3     1     2

         num(j, m) = num(j, m + 1)             |

         num(j, m + 1) = temp                 2|  6     4     5

     End If                                     |

   Next m                                     3|  7     9     8

 Next j

picBox.Cls

picBox.Print num(3, 2)

(A)      4

(B)       3

(C)       8

(D)      9

(E)       7