Public Class MyForm Private Sub AddWorkshop_Click(sender As Object, e As EventAr
ID: 3791943 • Letter: P
Question
Public Class MyForm
Private Sub AddWorkshop_Click(sender As Object, e As EventArgs) Handles AddWorkshop.Click
'Declare the variables
Dim daysOfworkShop As Integer = 0
Dim costWorkShop, costLodging, costTotal As Integer
Select Case daysOfworkShop
'Find the number of days of the workshop based on the selection
End Select
Select Case ListBoxWorkshop.SelectedIndex
'For case 0, 1 and 2, the number of days of workshop is 3
Case 0, 1, 2
daysOfworkShop = 3
'For case 3, the number of days of workshop is 5
Case 3
daysOfworkShop = 5
'For case 4, the number of days of workshop is 1
Case 4
daysOfworkShop = 1
'If there is no selection of Workshop and Training Location, provide a warning message
Case Else
MessageBox.Show("Pick a Workshop and Training location",
"Incomplete Selection", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
'This will unselect the selected location
ListBoxLocation.SetSelected(0, False)
Exit Sub
End Select
'Compute cost for the Workshop
costWorkShop = CalculateCostWorkShop
(ListBoxWorkshop.SelectedIndex)
'Compute cost for Lodging at selected Location
costLodging = calculateCostLodging
(daysOfworkShop)
'Check whether the location selection is made or not. If location
'selection in not made then the costLodging is zero
If costLodging = 0 Then
Exit Sub
End If
'Computing the costTotal of the Workshop
costTotal = costWorkShop + costLodging
'Show the Costs in the ListBox Cost
ListBoxCosts.Items.Add(costTotal.ToString("c2"))
Reset()
End Sub
Private Sub CalculateTotal_Click(sender As Object, e As EventArgs) Handles CalculateTotal.Click
'Declate all related variables
Dim totalValue As Double
'When the CalculateTotal button is pressed, compute the total costs of all the workshops
'For Loop To Add the total cost For all the workshops And show result In TextBoxTotal.
For Each decAdded As Decimal In
Me.ListBoxCosts.Items
totalValue += Double.Parse(decAdded)
Next
'Show the Total Costs in the TextBoxTotal
TextBoxTotal.Text = totalValue.ToString("c2")
End Sub
Private Sub ResetButton_Click(sender As Object, e As EventArgs) Handles ResetButton.Click
'This resets all fields
Reset()
'Clear listBoxes
ListBoxCosts.Items.Clear()
'Clears the textBox
TextBoxTotal.Text = ""
End Sub
Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
'Closes the form
Me.Close()
End Sub
'Function calculate CostWorkShop
Private Function calculateCostWorkShop(ByVal workShopNumber As Integer) As Integer
'Declaration of variable
Dim costWorkShop As Integer = 0
'Select Case for cost of workshop for each work shop.
'Find cost of selected workshop
Select Case workShopNumber
'For workshop on handling stress
Case 0
costWorkShop = 595
'For Workshop on Time Management
Case 1
costWorkShop = 695
'For Workshop on Supervision Skills
Case 2
costWorkShop = 995
'For Workshop on Negotiation
Case 3
costWorkShop = 1295
'For Workshop on how to Interview
Case 4
costWorkShop = 395
End Select
'Return the cost for selected workshop
Return costWorkShop
End Function
'Function calculateCostLodging
'Computes the cost for lodging at the selected location
Private Function calculateCostLodging(ByVal daysStay As Integer) As Integer
'Declaration of variables
Dim costStay As Integer
'Checks if the location is selected or not
If ListBoxLocation.SelectedIndex = -1 Then
MessageBox.Show("Pick a Training Location", "Incomplete Selection", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
Return 0
End If
'Compute and return the cost for lodging
Select Case ListBoxLocation.SelectedIndex
'Training Location Austin
Case 0
costStay = 95 * daysStay
'Training Location Chicago
Case 1
costStay = 125 * daysStay
'Training Location Dallas
Case 2
costStay = 110 * daysStay
'Training Location Orlando
Case 3
costStay = 100 * daysStay
'Training Location Phoenix
Case 4
costStay = 92 * daysStay
'Training Location Raleigh
Case 5
costStay = 90 * daysStay
End Select
Return costStay
End Function
'Function for Resetting
Private Function reset()
'resets the workshop listboxes
ListBoxWorkshop.SetSelected(0, False)
'Resets the location listbox
ListBoxLocation.SetSelected(0, False)
Return Nothing
End Function
End Class
The part of the code that is in bold and italics is coming up as incorrect when im trying to build this program with Visual Basic. Please tell me what im doing wrong
Explanation / Answer
Public Class MyForm
Private Sub AddWorkshop_ClickHandles AddWorkshop.Click
'Declare the variables
Dim daysOfworkShop As Integer = 0
Dim costWorkShop, costLodging, costTotal As Integer
Select Case daysOfworkShop
'Find the number of days of the workshop based on the selection
End Select
Select Case ListBoxWorkshop.SelectedIndex
'For case 0, 1 and 2, the number of days of workshop is 3
Case 0, 1, 2
daysOfworkShop = 3
'For case 3, the number of days of workshop is 5
Case 3
daysOfworkShop = 5
'For case 4, the number of days of workshop is 1
Case 4
daysOfworkShop = 1
'If there is no selection of Workshop and Training Location, provide a warning message
Case Else
MessageBox.Show("Pick a Workshop and Training location",
"Incomplete Selection", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
'This will unselect the selected location
ListBoxLocation.SetSelected(0, False)
Exit Sub
End Select
'Compute cost for the Workshop
costWorkShop = CalculateCostWorkShop
(ListBoxWorkshop.SelectedIndex)
'Compute cost for Lodging at selected Location
cost Lodging = calculate Cost Lodging
(daysOfworkShop)
'Check whether the location selection is made or not. If location
'selection in not made then the costLodging is zero
If costLodging = 0 Then
Exit Sub
End If
'Computing the costTotal of the Workshop
costTotal = costWorkShop + costLodging
'Show the Costs in the ListBox Cost
ListBoxCosts.Items.Add(costTotal.ToString("c2"))
Reset()
End Sub
Private Sub CalculateTotal_Click(sender As Object, e As EventArgs) Handles CalculateTotal.Click
'Declate all related variables
Dim totalValue As Double
'When the CalculateTotal button is pressed, compute the total costs of all the workshops
'For Loop To Add the total cost For all the workshops And show result In TextBoxTotal.
For Each decAdded As Decimal In
Me.ListBoxCosts.Items
totalValue += Double.Parse(decAdded)
Next
'Show the Total Costs in the TextBoxTotal
TextBoxTotal.Text = totalValue.ToString("c2")
End Sub
Private Sub ResetButton_Click(sender As Object, e As EventArgs) Handles ResetButton.Click
'This resets all fields
Reset()
'Clear listBoxes
ListBoxCosts.Items.Clear()
'Clears the textBox
TextBoxTotal.Text = ""
End Sub
Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
'Closes the form
Me.Close()
End Sub
'Function calculate CostWorkShop
Private Function calculateCostWorkShop(ByVal workShopNumber As Integer) As Integer
'Declaration of variable
Dim costWorkShop As Integer = 0
'Select Case for cost of workshop for each work shop.
'Find cost of selected workshop
Select Case workShopNumber
'For workshop on handling stress
Case 0
costWorkShop = 595
'For Workshop on Time Management
Case 1
costWorkShop = 695
'For Workshop on Supervision Skills
Case 2
costWorkShop = 995
'For Workshop on Negotiation
Case 3
costWorkShop = 1295
'For Workshop on how to Interview
Case 4
costWorkShop = 395
End Select
'Return the cost for selected workshop
Return costWorkShop
End Function
'Function calculateCostLodging
'Computes the cost for lodging at the selected location
Private Function calculateCostLodging(ByVal daysStay As Integer) As Integer
'Declaration of variables
Dim costStay As Integer
'Checks if the location is selected or not
If ListBoxLocation.SelectedIndex = -1 Then
MessageBox.Show("Pick a Training Location", "Incomplete Selection", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
Return 0
End If
'Compute and return the cost for lodging
Select Case ListBoxLocation.SelectedIndex
'Training Location Austin
Case 0
costStay = 95 * daysStay
'Training Location Chicago
Case 1
costStay = 125 * daysStay
'Training Location Dallas
Case 2
costStay = 110 * daysStay
'Training Location Orlando
Case 3
costStay = 100 * daysStay
'Training Location Phoenix
Case 4
costStay = 92 * daysStay
'Training Location Raleigh
Case 5
costStay = 90 * daysStay
End Select
Return costStay
End Function
'Function for Resetting
Private Function reset()
'resets the workshop listboxes
ListBoxWorkshop.SetSelected(0, False)
'Resets the location listbox
ListBoxLocation.SetSelected(0, False)
Return Nothing
End Function
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.