Learning about running total

Crash0141

New member
Joined
May 1, 2006
Messages
2
Programming Experience
Beginner
Find below my code, my problem is that I need txtTotalOut.text to equal the sum of multiple workshops selected. I am aware how to do it if I would only have one workshop, but if more than one is selected I do not know how to do it.

Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
End
End Sub

Private Sub cmdReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReset.Click
Workshop.SelectedIndex = -1
cities.SelectedIndex = -1
Costs.Items.Clear()
lblTotalOut.Text = ""
End Sub

Private
Sub CalcAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcAdd.Click

'If nothing is selected
If Workshop.SelectedIndex = -1 Then
MessageBox.Show("Please Select a Workshop", "Workshop Needed")
Exit Sub
End If

If cities.SelectedIndex = -1 Then
MessageBox.Show("Please Select a Location", "Location Needed")
Exit Sub
End If

'Registration Fees
Const stress = 595
Const time = 695
Const skills = 995
Const negotiation = 1295
Const interview = 395

'Lodging Fees
Const austin = 95
Const chicago = 125
Const dallas = 110
Const orlando = 100
Const phoenix = 92
Const raleigh = 90

'Days
Const stressdays = 3
Const timedays = 3
Const superdays = 3
Const negotiationdays = 5
Const interviewdays = 1

Dim workshopinput As String
workshopinput = Workshop.SelectedItem
Dim lodging As String
lodging = cities.SelectedItem

'Workshop Stress with Location
If workshopinput = Workshop.Items(0) Then
If lodging = cities.Items(0) Then
Costs.Items.Add(FormatCurrency(stress + (austin * stressdays)))
ElseIf lodging = cities.Items(1) Then
Costs.Items.Add(FormatCurrency(stress + (chicago * stressdays)))
ElseIf lodging = cities.Items(2) Then
Costs.Items.Add(FormatCurrency(stress + (dallas * stressdays)))
ElseIf lodging = cities.Items(3) Then
Costs.Items.Add(FormatCurrency(stress + (orlando * stressdays)))
ElseIf lodging = cities.Items(4) Then
Costs.Items.Add(FormatCurrency(stress + (phoenix * stressdays)))
ElseIf lodging = cities.Items(5) Then
Costs.Items.Add(FormatCurrency(stress + (raleigh * stressdays)))
End If
End If

'Workshop Time with location
If workshopinput = Workshop.Items(1) Then
If lodging = cities.Items(0) Then
Costs.Items.Add(FormatCurrency(time + (austin * timedays)))
ElseIf lodging = cities.Items(1) Then
Costs.Items.Add(FormatCurrency(time + (chicago * timedays)))
ElseIf lodging = cities.Items(2) Then
Costs.Items.Add(FormatCurrency(time + (dallas * timedays)))
ElseIf lodging = cities.Items(3) Then
Costs.Items.Add(FormatCurrency(time + (orlando * timedays)))
ElseIf lodging = cities.Items(4) Then
Costs.Items.Add(FormatCurrency(time + (phoenix * timedays)))
ElseIf lodging = cities.Items(5) Then
Costs.Items.Add(FormatCurrency(time + (raleigh * timedays)))
End If
End If

'Workshop Supervision with location
If workshopinput = Workshop.Items(2) Then
If lodging = cities.Items(0) Then
Costs.Items.Add(FormatCurrency(skills + (austin * superdays)))
ElseIf lodging = cities.Items(1) Then
Costs.Items.Add(FormatCurrency(skills + (chicago * superdays)))
ElseIf lodging = cities.Items(2) Then
Costs.Items.Add(FormatCurrency(skills + (dallas * superdays)))
ElseIf lodging = cities.Items(3) Then
Costs.Items.Add(FormatCurrency(skills + (orlando * superdays)))
ElseIf lodging = cities.Items(4) Then
Costs.Items.Add(FormatCurrency(skills + (phoenix * superdays)))
ElseIf lodging = cities.Items(5) Then
Costs.Items.Add(FormatCurrency(skills + (raleigh * superdays)))
End If
End If

'Workshop Negotiation with location
If workshopinput = Workshop.Items(3) Then
If lodging = cities.Items(0) Then
Costs.Items.Add(FormatCurrency(negotiation + (austin * negotiationdays)))
ElseIf lodging = cities.Items(1) Then
Costs.Items.Add(FormatCurrency(negotiation + (chicago * negotiationdays)))
ElseIf lodging = cities.Items(2) Then
Costs.Items.Add(FormatCurrency(negotiation + (dallas * negotiationdays)))
ElseIf lodging = cities.Items(3) Then
Costs.Items.Add(FormatCurrency(negotiation + (orlando * negotiationdays)))
ElseIf lodging = cities.Items(4) Then
Costs.Items.Add(FormatCurrency(negotiation + (phoenix * negotiationdays)))
ElseIf lodging = cities.Items(5) Then
Costs.Items.Add(FormatCurrency(negotiation + (raleigh * negotiationdays)))
End If
End If

'Workshop Interview with location
If workshopinput = Workshop.Items(4) Then
If lodging = cities.Items(0) Then
Costs.Items.Add(FormatCurrency(interview + (austin * interviewdays)))
ElseIf lodging = cities.Items(1) Then
Costs.Items.Add(FormatCurrency(interview + (chicago * interviewdays)))
ElseIf lodging = cities.Items(2) Then
Costs.Items.Add(FormatCurrency(interview + (dallas * interviewdays)))
ElseIf lodging = cities.Items(3) Then
Costs.Items.Add(FormatCurrency(interview + (orlando * interviewdays)))
ElseIf lodging = cities.Items(4) Then
Costs.Items.Add(FormatCurrency(interview + (phoenix * interviewdays)))
ElseIf lodging = cities.Items(5) Then
Costs.Items.Add(FormatCurrency(interview + (raleigh * interviewdays)))
End If
End If
End Sub

Private Sub cmdCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalc.Click
THIS IS WHERE I DO NOT KNOW WHAT TO PUT

End Sub

As stated before how do i get the total of workshops selected in my far right list box to add up and be displayed in the lbl when cmdCalc is clicked. My professor said to look up a running total, but I havent found anything at this point! Please feel free to email at crash0141@aol.com. Thanks for your help in advance!!!
 
Here is what I ended up doing

In case someone else has the same problem or is just curious, here is my code:

Private Sub cmdCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalc.Click
Dim i As Integer = Costs.Items.Count
Dim count As Integer
Dim total As Decimal
Dim sales As Decimal
Do Until i = 0
sales = Costs.Items(count)
total += sales
count += 1
i -= 1
Loop
lblTotalOut.Text = FormatCurrency(total)
End Sub
 
Back
Top