Public Class Form1
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
'Declare values from both listboxes
Dim Day, Fee, Stay, Total As Integer
'Workshop selection
Dim workshop As String = lstWorkshop.SelectedIndex()
If lstWorkshop.SelectedItem = "Handling Stress" Then
Day = 3
Fee = 595
ElseIf lstWorkshop.SelectedItem = "Time Management" Then
Day = 3
Fee = 695
ElseIf lstWorkshop.SelectedItem = "Supervision Skills" Then
Day = 3
Fee = 995
ElseIf lstWorkshop.SelectedItem = "Negotiation" Then
Day = 5
Fee = 1295
ElseIf lstWorkshop.SelectedItem = "How to Interview" Then
Day = 1
Fee = 395
ElseIf lstWorkshop.SelectedItem Is Nothing Then
MsgBox("Please choose a workshop first")
End If
'Location selection
Dim location As String = lstLocation.SelectedIndex()
If lstLocation.SelectedItem = "Austin" Then
Stay = Day * 95
ElseIf lstLocation.SelectedItem = "Chicago" Then
Stay = Day * 125
ElseIf lstLocation.SelectedItem = "Dallas" Then
Stay = Day * 110
ElseIf lstLocation.SelectedItem = "Orlando" Then
Stay = Day * 100
ElseIf lstLocation.SelectedItem = "Phoenix" Then
Stay = Day * 92
ElseIf lstLocation.SelectedItem = "Raleigh" Then
Stay = Day * 90
ElseIf lstLocation.SelectedItem Is Nothing Then
MsgBox("Please choose a location first")
End If
'Total cost
Total = Stay + Fee
'Display in list box
lstCost.Items.Add(Total.ToString("c"))
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lstWorkshop.SetSelected(0, False)
lstLocation.SetSelected(0, False) ' clear all listboxes and Total label
lstCost.Items.Clear()
lblTCost.Text = ""
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close() 'exit application
End Sub
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
End Sub
End Class
Outputting total to label problem
Page 1 of 12 Replies - 273 Views - Last Post: 07 March 2012 - 06:48 PM
#1
Outputting total to label problem
Posted 07 March 2012 - 06:36 PM
I am 99.9% done my code but I am stuck on trying to get the sum of numbers to output to a label. I have a label box lblTcost that I would like to have the total of my list box lstCost placed into there. I have tried several things and keeps crashing or just not working at that part. I have used the debugger but since I know the line is wrong any ways that not helping. I though this line would work lblTcost.Text = lstCost.ToString("c") was the proper way but it isn't. SO if anyone wouldn't mind letting me know where I am going wrong it would be appreciated. Here is my completed code
Replies To: Outputting total to label problem
#2
Re: Outputting total to label problem
Posted 07 March 2012 - 06:47 PM
This might be just me being tried but is there something missing here ?
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
End Sub
#3
Re: Outputting total to label problem
Posted 07 March 2012 - 06:48 PM
OK, I'm not sure what all is in lstCost. But assuming you just add the item once then you will need to specify it's index to get the value.
lblCost.Text = lstCost.Item(0).ToString("c")
again, I just scanned what you have here but it appears you're holding the total in the variable "Total" and then adding that to a listbox. If there is more than one item in that list you will have to iterate through the list with a for...next loop adding them together. If you are not adding multiple items to lstCost then Total hold the value you want so you could just use
lblCost.Text = Total.ToString("c")
lblCost.Text = lstCost.Item(0).ToString("c")
again, I just scanned what you have here but it appears you're holding the total in the variable "Total" and then adding that to a listbox. If there is more than one item in that list you will have to iterate through the list with a for...next loop adding them together. If you are not adding multiple items to lstCost then Total hold the value you want so you could just use
lblCost.Text = Total.ToString("c")
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|