1. Determine the output displayed when the button is clicked.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
‘Triple a number
Dim num As Double = 5
lstOutput.Items.Add(Triple(num))
lstOutput.Items.Add (num)
End Sub
Function Triple(ByVal x As Double) As Double
Dim num As Double = 3
Return num * x
End Function
2. Determine the output displayed when the button is clicked.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim states, senators As Double
States = 50
Senators = 2
Senate(states * senators)
End Sub
Sub Senate (ByVal num as Double)
txtBox.Text = “the number of U.S. Senators is “ & num
End Sub
3. Find the errors.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim word As String, number As Double
word = “seven”
number = 7
Display (word, number)
End Sub
Sub Display(ByVal num As Double, ByVal term As String)
textOutput.Text = num & “ “ & term
End Sub
4. Rewrite the program so input, processing, and output are each performed by calls to Sub procedures.
Private Sub btnCompute_Click(...) Handles btnCompute.Click
‘Information about trees
Dim num As Integer = 7
Tree = “redwood”
ht = 362
lstBox.Items.Add(“The tallest “ & tree & “ tree in the U. S, is “ & ht & & “ feet.”)
tree = “pine”
ht = 223
lstBox.Items.Add(“The tallest “ & tree & “ tree in the U. S. is “ & ht & “ feet.”)
End Sub
5. Determine the output displayed when the button is clicked.
Private Sub btnDetermine_Click(...) Handles btnDetermine.Click
Dim word As String = “”
Dim num As Integer
GetFacts(word, num)
txtOutput.text = “The first “ & num & “ letters of “ & word & “ are “ & BegOfWord(word, num) & “.”
End Sub
Sub GetFacts(ByRef w As String, ByRef num As Integer)
w = InputBox(“enter a word: “)
n = CInt(InputBox(“Enter a number less than the length of the word: “))
End Sub
Function BefOfWiord(ByVal word As String, ByVal num As Integer) As String
Return word.Substring(0, num)
End Function
(Assume the two responses are Education and 3.)
6. Determine the output displayed when the button is clicked.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim price, markdown, salesTax, finalCost as Double
InputData(price, finalCost)
finalCost = CostOfItem(price, markdown, salesTax)
DisplayOutput(price, finalCost)
End Sub
Sub InputData (ByRef price As Double, ByRef markdown As Double, ByRef salesTax As Double)
Price = CDbl(InputBox(“Price of item: “)
Markdown = CDbl (InputBox(“Percentage discount: “))
salesTax = CDbl(InputBox(“Percentage state sales tax: “))
End Sub
Function CostOfItem(ByVal pr As Double, ByVal md As Double, ByVal st As Double) As Double
Dim reducedPrice, cost As Double
reducedPrice = pr – ((md/100) * pr)
cost = reducedPrice + ((st / 100) * reducedPrice)
Return cost
End Function
(Assume the three responses are 125, 20, and 6)
7. Identify the errors.
Private Sub btnDisplay_Click(...) Handles btnDispla ...
1. Determine the output displayed when the button is clicked.P.docx
1. 1. Determine the output displayed when the button is clicked.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
‘Triple a number
Dim num As Double = 5
lstOutput.Items.Add(Triple(num))
lstOutput.Items.Add (num)
End Sub
Function Triple(ByVal x As Double) As Double
Dim num As Double = 3
Return num * x
End Function
2. Determine the output displayed when the button is clicked.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim states, senators As Double
States = 50
Senators = 2
Senate(states * senators)
End Sub
Sub Senate (ByVal num as Double)
txtBox.Text = “the number of U.S. Senators is “ & num
End Sub
3. Find the errors.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim word As String, number As Double
word = “seven”
number = 7
Display (word, number)
End Sub
Sub Display(ByVal num As Double, ByVal term As String)
2. textOutput.Text = num & “ “ & term
End Sub
4. Rewrite the program so input, processing, and output are each
performed by calls to Sub procedures.
Private Sub btnCompute_Click(...) Handles btnCompute.Click
‘Information about trees
Dim num As Integer = 7
Tree = “redwood”
ht = 362
lstBox.Items.Add(“The tallest “ & tree & “ tree in the U. S, is
“ & ht & & “ feet.”)
tree = “pine”
ht = 223
lstBox.Items.Add(“The tallest “ & tree & “ tree in the U. S. is
“ & ht & “ feet.”)
End Sub
5. Determine the output displayed when the button is clicked.
Private Sub btnDetermine_Click(...) Handles
btnDetermine.Click
Dim word As String = “”
Dim num As Integer
GetFacts(word, num)
txtOutput.text = “The first “ & num & “ letters of “ & word &
“ are “ & BegOfWord(word, num) & “.”
End Sub
Sub GetFacts(ByRef w As String, ByRef num As Integer)
w = InputBox(“enter a word: “)
n = CInt(InputBox(“Enter a number less than the length of
the word: “))
End Sub
Function BefOfWiord(ByVal word As String, ByVal num As
Integer) As String
3. Return word.Substring(0, num)
End Function
(Assume the two responses are Education and 3.)
6. Determine the output displayed when the button is clicked.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim price, markdown, salesTax, finalCost as Double
InputData(price, finalCost)
finalCost = CostOfItem(price, markdown, salesTax)
DisplayOutput(price, finalCost)
End Sub
Sub InputData (ByRef price As Double, ByRef markdown As
Double, ByRef salesTax As Double)
Price = CDbl(InputBox(“Price of item: “)
Markdown = CDbl (InputBox(“Percentage discount: “))
salesTax = CDbl(InputBox(“Percentage state sales tax: “))
End Sub
Function CostOfItem(ByVal pr As Double, ByVal md As
Double, ByVal st As Double) As Double
Dim reducedPrice, cost As Double
reducedPrice = pr – ((md/100) * pr)
cost = reducedPrice + ((st / 100) * reducedPrice)
Return cost
End Function
(Assume the three responses are 125, 20, and 6)
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
4. 'Compute twice the length of a string
Dim len As Integer
Return len = 2 * w.Length
End Function
Determine the output displayed when the button is clicked.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim num As Double = 0
Dim max As Double = -1
Dim prompt As String = “ Enter a nonnegative number. “ &
Enter -1 to terminate entering numbers.”
Num = CDbl(Input Box(prompt))
Do While num >= 0
If num > max Then
Max = num
End If
Num = CDbl(InputBox(prompt))
Loop
If max <> -1 Then
MessageBox.Show(“Maximum number: “ & max)
Else
MessageBox.Show(“No numbers were entered.”)
End If
Assu;me that the responses are 4, 7, 3, and -1)
2. Replace each phrase containing "Until" with an equivalent
phrase containing "While", and vice versa. For instance, the
phrase (Until sum = 100) would be replaced by (While sum <>
100).
While (ans = "Y") And (n < 7)
3. Determine the output displayed when the button is clicked.
5. Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim word As String = “courage”
Dim letter As String = “”
Dim numVowels As Integer = 0
For i As Integer = 0 To word.length – 1
Letter = word.Substring(I, 1)
If IsVowel (letter) Then
numVowels += 1
End If
Next
txtBox.Text = CStr(numVowels)
End Sub
Function IsVowel(ByVal letter As String) As Boolean
Letter = letter.ToUpper
If (letter = “A” Or (letter = “E”) Or (letter = “I”) Or (letter =
“O”) Or (letter = “U”) Then
Return True
Else
Return False
End If
End Function