Cs116-REVISION Questions - Done By:Mr. Mustafa Radaideh - Final Revisions
Cs116-REVISION Questions - Done By:Mr. Mustafa Radaideh - Final Revisions
For each of the following questions choose (a) for true and (b) for false, and code your choice in the
answer sheet.
1. Each argument in a Call statement must have the same name as the corresponding parameter in the
corresponding Sub statement.
3. Both Sub and Function procedures are accessed through the Call statement.
4. When a general sub procedure is used, the number of arguments must equal the number of parameters.
5. Suppose you want to write a procedure that takes three numbers, num1, num2, and num3; and returns
their sum, product, and average. It is best to use a Function procedure for this task.
7. Parallel arrays are two or more arrays that have corresponding elements.
8. The statement Dim state(50)has the same effect as the statement Dim state(1 To 50).
9. Consider the following Dim and assignment statements for myArray(). The assignment statement will
cause a "Subscript out of range" error.
Dim myArray(1 To 50) As Single
myArray(34) = 51
Arguments passed to this sub procedure are passed by value rather than by reference.
For each of the following questions choose the best possible answer from choices (a) through (d), and
code your choice in the answer sheet.
11. What is wrong with the following Call statement and its corresponding Sub statement?
13. 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.
14. 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
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
Cs116- REVISION Questions – Done By:Mr. Mustafa Radaideh – Final Revisions
15. What will be the output of the following program when the command button is clicked?
Private Sub cmdButton_Click()
Dim number As Single
picBox.Cls
number = 3
Call SquareAndDouble(number)
picBox.Print number
End Sub
Private Sub SquareAndDouble(myVar As Single)
myVar = myVar myVar
myVar = myVar + myVar
End Sub
(A) 3
(B) 18
(C) 36
(D) 0
16. Consider the following event procedure that calls a user-defined function named Cube, which
returns the cube of a number.
Private Sub cmdButton_Click()
Dim num As Single, result As Single
num = Val(InputBox("Enter a number to cube:"))
result = Cube(num)
picBox.Print "The cube of"; num; "is"; result
End Sub
Which of the following is a correct Function definition for Cube?
1. Private Function Cube(var As Single) As Single
Cube = var ^ 3
End Function
17. What will be the output of the following program when the command button is clicked?
Private Sub cmdButton_Click()
Dim word As String, result As String
picBox.Cls
word = "Benjamin"
result = Rotate(word)
result = Rotate(result & word)
result = Rotate(result)
picBox.Print result
End Sub
Private Function Rotate(var As String) As String
Dim varlength As Integer
varlength = Len(var)
Rotate = Mid(var, 2, varlength - 1) & Left(var, 1)
End Function
(A) jaminBBenjaminen
(B) BenjaminBenjamin
(C) njaminBe
(D) No output.
18. 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
19. 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
21. 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
24. Given the Dim statement below, which set of statements will initialize all elements of myArray()
to 100?
Dim myArray(0 To 100) As Single
(A) myArray = 100
(B) For i = 0 To 100
(i) = 100
Next i
(C) For j = 0 to 100
myArray(j) = 100
Next j
(D) myArray() is already initialized to 100 by the ReDim statement.