Hello All, I am new to programming and I apologize in advance if I am out of protocol in any way shape or fashion. My problem is that I have a program where you select an option from two different list boxes which will in turn populate a third list box with a numeric number when you click a button. Then I have a calculate button that is supposed to add all the numbers that were populated in the third list box. I can only get the first item and the last item from the third list box to be added correctly. I cannot get all the numbers in between added. I am hoping someone might help me with my problem. I think my issue is how I have my loop set up but I cannot figure it out. Thanks in advance, I have taken the liberty of adding my source code at the bottom.
[CODE=vbnet]Public Class Form1
Private Sub btnAddWorkshop_ Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnAddWorkshop. Click
' Declaring Items for Calculations
Dim RegistrationFee As Integer
Dim LodgingFee As Integer
Dim Days As Integer
Dim inttest2 As Integer
' Getting User selected Workshop and Number of Days for workshop
If lstWorkshop.Sel ectedItem = "Handling Stress" Then
RegistrationFee = 595
Days = 3
ElseIf lstWorkshop.Sel ectedItem = "Time Management" Then
RegistrationFee = 695
Days = 3
ElseIf lstWorkshop.Sel ectedItem = "Supervisio n Skills" Then
RegistrationFee = 995
Days = 3
ElseIf lstWorkshop.Sel ectedItem = "Negotiatio n" Then
RegistrationFee = 1295
Days = 5
ElseIf lstWorkshop.Sel ectedItem = "How to Interview" Then
RegistrationFee = 395
Days = 1
End If
' Getting User selected Locations for Workshop
If lstLocation.Sel ectedItem = "Austin" Then
LodgingFee = 95
ElseIf lstLocation.Sel ectedItem = "Chicago" Then
LodgingFee = 125
ElseIf lstLocation.Sel ectedItem = "Dallas" Then
LodgingFee = 110
ElseIf lstLocation.Sel ectedItem = "Orlando" Then
LodgingFee = 100
ElseIf lstLocation.Sel ectedItem = "Phoenix" Then
LodgingFee = 92
ElseIf lstLocation.Sel ectedItem = "Raleigh" Then
LodgingFee = 90
End If
' Populate the Costs List Box
inttest2 = lstCosts.Items. Add(Registratio nFee + (LodgingFee * Days).ToString)
Return
End Sub
Private Sub btnCalculate_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnCalculate.Cl ick
Dim intTest As Integer
Dim X As Integer = 1
' Display Error message if no workshop and selection have not been selected
If lstCosts.Items. Count = 0 Then
MessageBox.Show ("Please select a Workshop and Location!", "Roland Toussaint--Error")
Else
' I think my problem is here somewhere ******
' Add items from list for display
Do While X <> lstCosts.Items. Count
intTest = CInt(lstCosts.I tems(0)) + (lstCosts.Items (X))
X += 1
Loop
' Display total
lblTotalCost.Te xt = intTest
End If
End Sub
Private Sub btnReset_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnReset.Click
' Reset the list Boxes by deselecting the currently selected items
lstWorkshop.Sel ectedIndex = -1
lstLocation.Sel ectedIndex = -1
lstCosts.Items. Clear()
lblTotalCost.Te xt = String.Empty
End Sub
Private Sub btnExit_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles btnExit.Click
' Exit program by closing window
Me.Close()
End Sub
End Class[/CODE]
[CODE=vbnet]Public Class Form1
Private Sub btnAddWorkshop_ Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnAddWorkshop. Click
' Declaring Items for Calculations
Dim RegistrationFee As Integer
Dim LodgingFee As Integer
Dim Days As Integer
Dim inttest2 As Integer
' Getting User selected Workshop and Number of Days for workshop
If lstWorkshop.Sel ectedItem = "Handling Stress" Then
RegistrationFee = 595
Days = 3
ElseIf lstWorkshop.Sel ectedItem = "Time Management" Then
RegistrationFee = 695
Days = 3
ElseIf lstWorkshop.Sel ectedItem = "Supervisio n Skills" Then
RegistrationFee = 995
Days = 3
ElseIf lstWorkshop.Sel ectedItem = "Negotiatio n" Then
RegistrationFee = 1295
Days = 5
ElseIf lstWorkshop.Sel ectedItem = "How to Interview" Then
RegistrationFee = 395
Days = 1
End If
' Getting User selected Locations for Workshop
If lstLocation.Sel ectedItem = "Austin" Then
LodgingFee = 95
ElseIf lstLocation.Sel ectedItem = "Chicago" Then
LodgingFee = 125
ElseIf lstLocation.Sel ectedItem = "Dallas" Then
LodgingFee = 110
ElseIf lstLocation.Sel ectedItem = "Orlando" Then
LodgingFee = 100
ElseIf lstLocation.Sel ectedItem = "Phoenix" Then
LodgingFee = 92
ElseIf lstLocation.Sel ectedItem = "Raleigh" Then
LodgingFee = 90
End If
' Populate the Costs List Box
inttest2 = lstCosts.Items. Add(Registratio nFee + (LodgingFee * Days).ToString)
Return
End Sub
Private Sub btnCalculate_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnCalculate.Cl ick
Dim intTest As Integer
Dim X As Integer = 1
' Display Error message if no workshop and selection have not been selected
If lstCosts.Items. Count = 0 Then
MessageBox.Show ("Please select a Workshop and Location!", "Roland Toussaint--Error")
Else
' I think my problem is here somewhere ******
' Add items from list for display
Do While X <> lstCosts.Items. Count
intTest = CInt(lstCosts.I tems(0)) + (lstCosts.Items (X))
X += 1
Loop
' Display total
lblTotalCost.Te xt = intTest
End If
End Sub
Private Sub btnReset_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnReset.Click
' Reset the list Boxes by deselecting the currently selected items
lstWorkshop.Sel ectedIndex = -1
lstLocation.Sel ectedIndex = -1
lstCosts.Items. Clear()
lblTotalCost.Te xt = String.Empty
End Sub
Private Sub btnExit_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles btnExit.Click
' Exit program by closing window
Me.Close()
End Sub
End Class[/CODE]
Comment