13 Replies - 2264 Views - Last Post: 26 March 2011 - 06:08 PM Rate Topic: -----

#1 katy_white  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-March 11

Visual basic combo box and listbox total

Posted 26 March 2011 - 05:39 AM

Basically im really stuck on one part of the my coursework which is the total bit. Ive looked everywhere but i still have not found a coding that works. Basically i have 2 combo box's (cboUrban , cboUk) and 2 add buttons for each (btnAdd1, btnAdd2) and a lstTrack box. The user selects a song from each catagory and adds the song by clicking on add track button for each combo box the song then appears on the lstTrack box where a total has to be displayed. however i can not find a code for this could you please help mee!!! each track costs 1.00

This is my coding so far for each button

Public Class frmMusicStars


    Private Sub btnTrack1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrack1.Click
       

        If (cboUrban.SelectedIndex.ToString >= 0) Then
            lstTracks.Items.Add(cboUrban.SelectedItem.ToString)

        End If

       
    End Sub

    Private Sub btnTrack2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrack2.Click


        If (cboUk.SelectedIndex.ToString >= 0) Then
            lstTracks.Items.Add(cboUk.SelectedItem.ToString)
        End If

    End Sub


Mode Edit:
:code:!!!

Is This A Good Question/Topic? 0
  • +

Replies To: Visual basic combo box and listbox total

#2 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 06:40 AM

View Postkaty_white, on 26 March 2011 - 07:39 AM, said:

Basically im really stuck on one part of the my coursework which is the total bit. Ive looked everywhere but i still have not found a coding that works. Basically i have 2 combo box's (cboUrban , cboUk) and 2 add buttons for each (btnAdd1, btnAdd2) and a lstTrack box. The user selects a song from each catagory and adds the song by clicking on add track button for each combo box the song then appears on the lstTrack box where a total has to be displayed. however i can not find a code for this could you please help mee!!! each track costs 1.00

This is my coding so far for each button

Public Class frmMusicStars


Private Sub btnTrack1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrack1.Click


If (cboUrban.SelectedIndex.ToString >= 0) Then
lstTracks.Items.Add(cboUrban.SelectedItem.ToString)

End If


End Sub

Private Sub btnTrack2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrack2.Click


If (cboUk.SelectedIndex.ToString >= 0) Then
lstTracks.Items.Add(cboUk.SelectedItem.ToString)
End If

End Sub


Is it not adding it to the ListBox? Are you getting any errors?

Try the following code and tell me if you get any errors.
Public Class frmMusicStars


    Private Sub btnTrack1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrack1.Click
       

        If cboUrban.SelectedIndex.ToString <> Nothing Then
            lstTracks.Items.Add(cboUrban.SelectedItem.ToString)

        End If

       
    End Sub

    Private Sub btnTrack2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrack2.Click


        If cboUk.SelectedIndex <> Nothing Then
            lstTracks.Items.Add(cboUk.SelectedItem.ToString)
        End If

    End Sub
End Class


Was This Post Helpful? 1
  • +
  • -

#3 katy_white  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-March 11

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 06:57 AM

Hi, sorry i think you understood wrong. It is adding to the list box however i want a total of how much it costs so when it adds to the list box i also want a price to come up calculating how much it is. ? Im really stuck and i need to do this coursework as soon as possible.
So basically calculating the total cost when the track is added to the list box thank you please help

View Postkaty_white, on 26 March 2011 - 06:56 AM, said:

Hi, sorry i think you understood wrong. It is adding to the list box however i want a total of how much it costs so when it adds to the list box i also want a price to come up calculating how much it is. ? Im really stuck and i need to do this coursework as soon as possible.
So basically calculating the total cost when the track is added to the list box thank you please help


Basically if i press add track to list the track name will come up and at the bottom the label wil calculate how much it costs alltogether...each track will have to cost 1.00 so if i added 4 tracks the total will be 4.00

but i cant find a coding for that
Was This Post Helpful? 0
  • +
  • -

#4 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 07:27 AM

View Postkaty_white, on 26 March 2011 - 08:57 AM, said:

Hi, sorry i think you understood wrong. It is adding to the list box however i want a total of how much it costs so when it adds to the list box i also want a price to come up calculating how much it is. ? Im really stuck and i need to do this coursework as soon as possible.
So basically calculating the total cost when the track is added to the list box thank you please help

View Postkaty_white, on 26 March 2011 - 06:56 AM, said:

Hi, sorry i think you understood wrong. It is adding to the list box however i want a total of how much it costs so when it adds to the list box i also want a price to come up calculating how much it is. ? Im really stuck and i need to do this coursework as soon as possible.
So basically calculating the total cost when the track is added to the list box thank you please help


Basically if i press add track to list the track name will come up and at the bottom the label wil calculate how much it costs alltogether...each track will have to cost 1.00 so if i added 4 tracks the total will be £4.00

but i cant find a coding for that


Oh, thats simple.. Your gonna want to count every item and add a dollar to a total variable.
    Private Sub btnTrack2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrack2.Click


        If cboUk.SelectedIndex <> Nothing Then
            lstTracks.Items.Add(cboUk.SelectedItem.ToString)

            'Recalculate total amount.
            Dim total As Integer = 0
            For each i as string in lstTracks.Items
               total += 1 'Adds a dollar per track.
            Next 
            'total is the bill.
        End If

    End Sub



EDIT:
Since every song is a dollar, you could do this:
Dim total as Integer = lstTracks.Items.Count


This post has been edited by Amrykid: 26 March 2011 - 07:30 AM

Was This Post Helpful? 1
  • +
  • -

#5 katy_white  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-March 11

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 07:36 AM

View PostAmrykid, on 26 March 2011 - 07:27 AM, said:

View Postkaty_white, on 26 March 2011 - 08:57 AM, said:

Hi, sorry i think you understood wrong. It is adding to the list box however i want a total of how much it costs so when it adds to the list box i also want a price to come up calculating how much it is. ? Im really stuck and i need to do this coursework as soon as possible.
So basically calculating the total cost when the track is added to the list box thank you please help

View Postkaty_white, on 26 March 2011 - 06:56 AM, said:

Hi, sorry i think you understood wrong. It is adding to the list box however i want a total of how much it costs so when it adds to the list box i also want a price to come up calculating how much it is. ? Im really stuck and i need to do this coursework as soon as possible.
So basically calculating the total cost when the track is added to the list box thank you please help


Basically if i press add track to list the track name will come up and at the bottom the label wil calculate how much it costs alltogether...each track will have to cost 1.00 so if i added 4 tracks the total will be 4.00

but i cant find a coding for that


Oh, thats simple.. Your gonna want to count every item and add a dollar to a total variable.
    Private Sub btnTrack2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrack2.Click


        If cboUk.SelectedIndex <> Nothing Then
            lstTracks.Items.Add(cboUk.SelectedItem.ToString)

            'Recalculate total amount.
            Dim total As Integer = 0
            For each i as string in lstTracks.Items
               total += 1 'Adds a dollar per track.
            Next 
            'total is the bill.
        End If

    End Sub



EDIT:
Since every song is a dollar, you could do this:
Dim total as Integer = lstTracks.Items.Count


Thank youu soo much but i entered that code it works with no error how ever the total cost does not show on the label
Was This Post Helpful? 0
  • +
  • -

#6 katy_white  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-March 11

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 08:10 AM

Oww i found it thanks just had to add

lblPrice.Text = total.ToString("c")

Thank you another question relevant to this..so after adding up the total i finally get a total however i also have a remove button and when the user clicks on the remove button the track is removed... what is the subtract code for the remove button that takes away the total and if all tracks are removed leaves the user for 0.00?
Was This Post Helpful? 0
  • +
  • -

#7 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 09:09 AM

View Postkaty_white, on 26 March 2011 - 09:36 AM, said:

View PostAmrykid, on 26 March 2011 - 07:27 AM, said:

View Postkaty_white, on 26 March 2011 - 08:57 AM, said:

Hi, sorry i think you understood wrong. It is adding to the list box however i want a total of how much it costs so when it adds to the list box i also want a price to come up calculating how much it is. ? Im really stuck and i need to do this coursework as soon as possible.
So basically calculating the total cost when the track is added to the list box thank you please help

View Postkaty_white, on 26 March 2011 - 06:56 AM, said:

Hi, sorry i think you understood wrong. It is adding to the list box however i want a total of how much it costs so when it adds to the list box i also want a price to come up calculating how much it is. ? Im really stuck and i need to do this coursework as soon as possible.
So basically calculating the total cost when the track is added to the list box thank you please help


Basically if i press add track to list the track name will come up and at the bottom the label wil calculate how much it costs alltogether...each track will have to cost 1.00 so if i added 4 tracks the total will be £4.00

but i cant find a coding for that


Oh, thats simple.. Your gonna want to count every item and add a dollar to a total variable.
    Private Sub btnTrack2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrack2.Click


        If cboUk.SelectedIndex <> Nothing Then
            lstTracks.Items.Add(cboUk.SelectedItem.ToString)

            'Recalculate total amount.
            Dim total As Integer = 0
            For each i as string in lstTracks.Items
               total += 1 'Adds a dollar per track.
            Next 
            'total is the bill.
        End If

    End Sub



EDIT:
Since every song is a dollar, you could do this:
Dim total as Integer = lstTracks.Items.Count


Thank youu soo much but i entered that code it works with no error how ever the total cost does not show on the label


Total is a variable.. just assign it to a label.

EDIT: Use the same recalculation code in the remove button's code too. Just copy and paste it to the end.

This post has been edited by Amrykid: 26 March 2011 - 09:11 AM

Was This Post Helpful? 1
  • +
  • -

#8 katy_white  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-March 11

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 09:15 AM

Oww i found it thanks just had to add

[code]lblPrice.Text = total.ToString("c")[code]

Thank you another question relevant to this..so after adding up the total i finally get a total however i also have a remove button and when the user clicks on the remove button the track is removed... what is the subtract code for the remove button that takes away the total and if all tracks are removed leaves the user for 0.00? ???????
Was This Post Helpful? 0
  • +
  • -

#9 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 09:20 AM

View Postkaty_white, on 26 March 2011 - 11:15 AM, said:

Oww i found it thanks just had to add

lblPrice.Text = total.ToString("c")


Thank you another question relevant to this..so after adding up the total i finally get a total however i also have a remove button and when the user clicks on the remove button the track is removed... what is the subtract code for the remove button that takes away the total and if all tracks are removed leaves the user for 0.00? ???????

Use the same recalculation code in the remove button's code too. Just copy and paste it to the end.

Dim total as Integer = lstTracks.Items.Count



Its works both ways (for adding and subtracting).

This post has been edited by Amrykid: 26 March 2011 - 09:21 AM

Was This Post Helpful? 1
  • +
  • -

#10 katy_white  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-March 11

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 11:18 AM

what coding is used to make it go back to 0.00 when nothing is in the cart?
Was This Post Helpful? 0
  • +
  • -

#11 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 12:14 PM

View Postkaty_white, on 26 March 2011 - 01:18 PM, said:

what coding is used to make it go back to 0.00 when nothing is in the cart?

If you use the same segment I've said before in both your add track item and your remove track button, it will work.

If no items are in the listbox, it returns 0. The code segement would then return "0.00" if you use it with
lblPrice.Text = total.ToString("c")

Was This Post Helpful? 1
  • +
  • -

#12 katy_white  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-March 11

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 01:41 PM

Thanks alotttt...can anyone tell me where i can get information from on how to do a total invoice ? basically a reciept at the end saying what the user has ordereddd and the name etc. because ive conected my basket with a database that stores information now i need a final reciept been looking around but cant find any...anyone can help?
Was This Post Helpful? 0
  • +
  • -

#13 sbell1099  Icon User is offline

  • Inspiring StoryTeller
  • member icon

Reputation: 16
  • View blog
  • Posts: 685
  • Joined: 28-October 08

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 03:10 PM

Maybe use another form? Load it then display in a logical order using Labels and Listbox? Then just offer a print/save option.
Was This Post Helpful? 1
  • +
  • -

#14 katy_white  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 26-March 11

Re: Visual basic combo box and listbox total

Posted 26 March 2011 - 06:08 PM

how do i add the labels or the list box or anytype of item from another form to another form which will still indicate the total inside it or the tracks inside it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1