2 Replies - 273 Views - Last Post: 07 March 2012 - 06:48 PM Rate Topic: -----

#1 biggmann  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 77
  • Joined: 02-February 10

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

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





Is This A Good Question/Topic? 0
  • +

Replies To: Outputting total to label problem

#2 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 93
  • View blog
  • Posts: 871
  • Joined: 15-October 10

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

Was This Post Helpful? 1
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,434
  • Joined: 25-September 09

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")
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1