• 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

Visual Basic form 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 creating a form application and i ran into a problem. I have 2 buttons 1 Order button and 1 Checkout Button. I also have 2 Listboxes, one for your order and the last one for your invoice. My problem is when i get to the second listbox. i get all the data over to there that i want however i need to change the extendedprice to an updated price from a discount. I also have 3 radio buttons for different discounts. when i click a radio button and hit the checkout button i cannot seem to get the discount to show up when i run it just stops at regular extended price in my second list box. any help would be very gratefull as i am still new to this but im trying to learn


Public Class Form1

   Private Sub btnorder_Click(sender As Object, e As EventArgs) Handles btnorder.Click
       Dim itemnumber As Decimal
       Dim price As Decimal
       Dim extendedprice As Decimal
       Dim quantity As Decimal
       itemnumber = txtitemnumber.Text
       quantity = txtquantity.Text
       extendedprice = price * quantity

       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

       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

       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

       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

       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

       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

       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

       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
   End Sub

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


       listinvoice.Items.Add(" Timber Tom’s Hardware 2016-10-11 6:30 pm")
       listinvoice.Items.AddRange(listorder.Items)


       If rbnodiscount.Checked Then
           listinvoice.Items.Add("No Discount")
       End If

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

       End If

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

   End Sub
End Class
 
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the ranch.

I'm not entirely sure what it is you are trying to do or what your problem is but your btncheckout_Click subroutine doesn't look right to me.


What do the two assignments do? extendedprice and discount haven't been assigned any values at this stage.

In your if statements you compute the discount and extendedprice but don't use the extendedprice after that, should that have been totalprice you were computing.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic