1. Determine the output displayed when the button is clicked.


Private Sub btnDisplay_Click(...) Handles btnDisplay.Click



Dim size As Double



size = 435



House(size)



lstOutput.Items.Add("of Representatives")



End Sub



Sub House(ByVal size As Double)



lstOutput.Items.Add(size & " members in the House")



End Sub



2. Determine the output displayed when the button is clicked.



Private Sub btnDisplay_Click(...) Handles btnDisplay.Click



Dim name As String = "Terry Jones"



Abbreviate(name)



txtOutput.Text = name



End Sub



Sub Abbreviate(ByRef a As String)



Dim b As Integer = a.IndexOf("")



a = a.SubString(0, 1) & " . " & a.SubString(b + 1, 1) & "."



End Sub



3. Find the errors.



Private Sub btnDisplay_Click(...) Handles btnDisplay.Click



Dim vowels As Integer 'Number of vowels



ExamineLetter(vowels)



ExamineLetter(vowels)



ExamineLetter(vowels)



txtOutput.Text = "The number of vowels is " & vowels



End Sub



Sub ExamineLetter(ByRef vowels As Integer)



Dim ltr As String



ltr = InputBox("Enter a letter.")



ltr = ltr.ToUpper



If (ltr = "A") Or (ltr = "E") Or (ltr = "I") Or _



(ltr = "O") Or (ltr = "U") Then



vowels += 1



End If



End Sub



(Assume the three responses are U, b, and a.)



4. Rewrite the program so input, processing, and output are each performed by calls to Sub procedures.



Private Sub btnCompute_Click(...) Handles btnCompute.Click



'Convert feet and inches to centimeters



Dim str As String



Dim feet, inches, totalInches, centimeters As Double



str = "Give the length in feet and inches. "



feet = CDbl(InputBox(str & "Enter the number of feet."))



inches = CDbl(InputBox(str & "Enter the number of inches. "))



totalInches = 12 * feet + inches



centimeters = 2.54 * totalInches



txtOutput.Text = "The length in centimeters is " & centimeters



End Sub



5. Determine the output displayed when the button is clicked.



Private Sub btnDetermine_Click(...) Handles btnDetermine.Click



Dim numOne, numTwo, numThree, numLowest As Double



numOne = CDbl(txtOne.Text)



numTwo = CDbl(txtTwo.Text)



numThree = CDbl(txtThree.Text)



numLowest = FindLowest(numOne, numTwo, numThree)



txtLowest.Text = CStr(numLowest)



End Sub



Function FindLowest(ByVal x As Double, ByVal y As Double, _



ByVal z As Double) As Double



'Find the lowest of three numbers denoted by x, y, and z



Dim lowest As Double



lowest = x



If y < lowest Then



lowest = y



End If



If z < lowest Then



lowest = z



End If



Return lowest



End Function



(Assume the first three text boxes contain the numbers 7, 4, and 3.)



6. Determine the output displayed when the button is clicked.



Private Sub btnDisplay_Click(...) Handles btnDisplay.Click



'Determine the day of the week from its number



Dim days As String, num As Integer



days = "SunMonTueWedThuFriSat"



num = CInt(InputBox("Enter the number of the day."))



txtOutput.Text = "The day is " & DayOfWk(days, num) & "."



End Sub



Function DayOfWk(ByVal x As String, ByVal n As Integer) As String



'x String containing 3-letter abbreviations of days



'n The number of the day



Dim position As Integer



position = 3 * n - 3



Return x.Substring(position, 3)



End Function



(Assume the response is 4.)



7. Identify the errors.



Private Sub btnDisplay_Click(...) Handles btnDisplay.Click



Dim word As String



word = InputBox("What is your favorite word?")



txtOutput.Text = "When the word is written twice, " & _



Twice(word) & " letters are used."



End Sub



Function Twice(ByVal w As String) As Integer



'Compute twice the length of a string



Dim len As Integer



Return len = 2 * w.Length