• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

vb subtotal problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello im trying to resolve a issue im having with my code. i want my second listbox to display a subtotal of all the items extended prices from my first listbox. i cant figoure out how to get the subtotal. please help


Public Class Form1
   Dim extendedprice As Decimal
   Dim subtotal As Decimal


   Private Sub btnorder_Click(sender As Object, e As EventArgs) Handles btnorder.Click
       Dim itemnumber As Decimal
       Dim price As Decimal
       Dim quantity As Decimal

       itemnumber = txtitemnumber.Text
       quantity = txtquantity.Text
       extendedprice = price * quantity

       'Item Number 100 displays Wrench
       If itemnumber = 100 Then
           extendedprice = 3.5 * quantity
           listorder.Items.Add("Item Number: 100")
           listorder.Items.Add("Description: Wrench")
           listorder.Items.Add("Quantity:" & quantity)
           listorder.Items.Add("Price: $3.50")
           listorder.Items.Add("Extended Price:" & extendedprice.ToString("c"))

       End If

       'Item Number 200 displays Pipe Wrench
       If itemnumber = 200 Then
           extendedprice = 5.75 * quantity
           listorder.Items.Add("Item Number: 200")
           listorder.Items.Add("Description: Pipe Wrench")
           listorder.Items.Add("Quantity:" & quantity)
           listorder.Items.Add("Price: $5.75")
           listorder.Items.Add("Extended Price:" & extendedprice.ToString("c"))
       End If

       'Item Number 300 displays Rip Saw
       If itemnumber = 300 Then
           extendedprice = 16.23 * quantity
           listorder.Items.Add("Item Number: 300")
           listorder.Items.Add("Description: Rip Saw")
           listorder.Items.Add("Quantity:" & quantity)
           listorder.Items.Add("Price: $16.23")
           listorder.Items.Add("Extended Price:" & extendedprice.ToString("c"))
       End If

       'Item Number 400 displays Framing Hammer
       If itemnumber = 400 Then
           extendedprice = 32.5 * quantity
           listorder.Items.Add("Item Number: 400")
           listorder.Items.Add("Description: Framing Hammer")
           listorder.Items.Add("Quantity:" & quantity)
           listorder.Items.Add("Price: $32.50")
           listorder.Items.Add("Extended Price:" & extendedprice.ToString("c"))
       End If

       'Item Number 500 displays Square
       If itemnumber = 500 Then
           extendedprice = 27.5 * quantity
           listorder.Items.Add("Item Number: 500")
           listorder.Items.Add("Description: Square")
           listorder.Items.Add("Quantity:" & quantity)
           listorder.Items.Add("Price: $27.50")
           listorder.Items.Add("Extended Price:" & extendedprice.ToString("c"))
       End If

       'Item Number 600 displays Solder
       If itemnumber = 600 Then
           extendedprice = 6.34 * quantity
           listorder.Items.Add("Item Number: 600")
           listorder.Items.Add("Description: Solder")
           listorder.Items.Add("Quantity:" & quantity)
           listorder.Items.Add("Price: $6.34")
           listorder.Items.Add("Extended Price:" & extendedprice.ToString("c"))
       End If

       'Item Number 700 displays Paste
       If itemnumber = 700 Then
           extendedprice = 4.26 * quantity
           listorder.Items.Add("Item Number: 700")
           listorder.Items.Add("Description: Paste")
           listorder.Items.Add("Quantity:" & quantity)
           listorder.Items.Add("Price: $4.26")
           listorder.Items.Add("Extended Price:" & extendedprice.ToString("c"))
       End If

       'Item Number 800 displays Screwdriver
       If itemnumber = 800 Then
           extendedprice = 11.77 * quantity
           listorder.Items.Add("Item Number: 800")
           listorder.Items.Add("Description: Screwdriver")
           listorder.Items.Add("Quantity:" & quantity)
           listorder.Items.Add("Price: $11.77")
           listorder.Items.Add("Extended Price:" & extendedprice.ToString("c"))
       End If

       ' Adds a line under the order
       listorder.Items.Add("--------------------------------------------")

       'Clears the Item Number Text Box & Quantity Text Box
       txtitemnumber.Text = ""
       txtquantity.Text = ""


   End Sub

   Private Sub btncheckout_Click(sender As Object, e As EventArgs) Handles btncheckout.Click
       Dim discount As Decimal
       Dim totalprice As Decimal


       discount = extendedprice - discount
       totalprice = extendedprice * discount




       listinvoice.Items.Add("Timber Tom’s Hardware")
       listinvoice.Items.Add(Date.Now)
       listinvoice.Items.Add("--------------------------------------------")




       listinvoice.Items.Add("Sub Total " & subtotal.ToString("c"))


       'no discount
       If rbnodiscount.Checked Then
           totalprice = extendedprice
           listinvoice.Items.Add("No Discount")
           listinvoice.Items.Add("Total Price:" & totalprice.ToString("c"))
       End If

       '10% discount
       If rb10discount.Checked Then
           discount = extendedprice * 0.1
           totalprice = extendedprice - discount
           listinvoice.Items.Add("10%Discount:" & discount.ToString("c"))
           listinvoice.Items.Add("Total Price:" & totalprice.ToString("c"))
       End If


       '15% discount
       If rb15discount.Checked Then
           discount = extendedprice * 0.15
           totalprice = extendedprice - discount
           listinvoice.Items.Add("15% Discount:" & discount.ToString("c"))
           listinvoice.Items.Add("Total Price:" & totalprice.ToString("c"))
       End If




   End Sub

   Private Sub btnclearitems_Click(sender As Object, e As EventArgs) Handles btnclearitems.Click

       'Clears Order List Box
       listorder.Items.Clear()

   End Sub

   Private Sub btnclearinvoice_Click(sender As Object, e As EventArgs) Handles btnclearinvoice.Click

       'Clears Invoice List Box
       listinvoice.Items.Clear()

   End Sub

   Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click

       'Asks if you want to exit
       If MsgBox("Are you sure you want to exit?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
           Application.Exit()

       End If
   End Sub
End Class
 
reply
    Bookmark Topic Watch Topic
  • New Topic