Add total from Access Database


  • I am making a calculator that will take a title of a book from a list box, find the book in a linked database and take the price of that book. The price would then be calculated as a subtotal of all the books in the list box and then add tax and a final total show in labels. It would all be started with the press of a button. I am stuck, this was where I started but it is not working.

      Private Sub Calc_Btn_Click(sender As Object, e As EventArgs) Handles Calc_Btn.Click
            Dim sum As Double
            For x As Integer = 0 To Cart_List.Items.Count - 1
                sum += Val(Cart_List.Items.Item(x).ToString)

            SubTot_lbl = sum.ToString

    Any help would be appreciated! I could be way off I am not sure. 

    Wednesday, April 5, 2017 2:08 PM

All replies

  • It is a very simple question therefore I think it is homework. 

    What you have to do is create a datatable with a TableAdapter

    Then you get with that a table. That you set to the Table as datasource of the listbox

    LB.DataSource = theDataTable

    The Name you set to the Displaymember
    LB.DisplayMember = "Name"

    and in the same way the price to the valuemember.

    The only code you need now in the method which handles the index changed event is

    Sum += Cdec(LB.Value)

    and then set sum to the label

    SubTot_lbl = Sum.ToString("9,99") (in English 9.99) 



    Wednesday, April 5, 2017 3:00 PM