Review

advertisement
Test 2
__________________________________
October
Name
Visual Basic
Review Questions
1. Write a function named Max that accepts two integer inputs A,B and returns the
maximum value of the two.
2. Where can a function be called?
3. Write a subroutine called addGrade which takes an input called newGrade and
adds it to the end of a Public
array Grades which currently has numGrades (also Public) entries. The value of
numGrades should be
increased by 1 and the first numGrades variables should be unchanged.
4. Where can a subroutine be called?
5. Describe an array.
6. How would the 6th component of Grades be accessed?
7. Describe a structure.
8. How would the field variable GPA be accessed if it belonged to a variable
nxtStudent of type Student where Student is a structure? Define
9. The subroutine below reads one line at a time from a text file.
• What is sr? _______________
• What does sr = System.IO.File.OpenText("Expense.txt") do?
_________________
• What is the name of the text file and where is it located?
______________
• How does exp get assigned a value and what is done with the value?
• _______________________________________________
Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRead.Click
'Declare stream reader
Dim sr As System.IO.StreamReader
'Connect to text file
sr = System.IO.File.OpenText("Expense.txt")
Dim exp As String = sr.ReadLine
Do While exp <> -1
lbExpenses.Items.Add(exp)
exp = sr.ReadLine
Loop
End Sub
10. Referring back to the btnRead_Click subroutine,
• When does it get launched? ____________________________
• What happens to the values read in? _____________________
3. In the subroutine below,
• What data type is total? _____________________________
• What is value of n? __________________________________
• Describe the action of the For loop.
1. _______________________________________________
2. _______________________________________________
• Write a Do While to accomplish the same task.
Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTotal.Click
Dim total As Double = 0
Dim n As Integer = lbExpenses.Items.Count - 1
For i As Integer = 0 To n
total += CDbl(lbExpenses.Items(i))
Next
lblTotal.Text &= " = " & total
End Sub
Download