3 Replies - 432 Views - Last Post: 12 October 2012 - 10:59 PM Rate Topic: -----

#1 Varlisk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 20-September 12

How to reset a price variable?

Posted 12 October 2012 - 05:14 PM

I'm supposed to be modifying a program that lists items and prices in a list box, when an item is clicked it is added to a second listbox. A total cost is then calculated based on the second list box. But I'm having an issue with the clear button.

The list box part (shortened to fit), this part works
Dim LineItem As RestaurantMenuItem

        LineItem = New RestaurantMenuItem
        LineItem.Name = "Item One"
        LineItem.Price = 1.00
        CafeMenu.Add(LineItem)

 For Each LineItem In CafeMenu
            ListBox1.Items.Add(LineItem.Name)
            ListBox2.Items.Add(LineItem.Price)



The calculate button:
Dim orderItem As RestaurantMenuItem
        Dim Total As Double
For Each orderItem In Order
            subTotal += orderItem.Price
            lblTotal.Text = total


Again, this works.

Now, the part that does NOT work:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ListBox3.Items.Clear()
        lblTotal.Text = "____________"
      End Sub


This is supposed to clear it.
It empties the listbox and sets the cost label to 0, but it doesn't reset the cost. If I add a 1.00 item, click calc, clear it, add a 1.00 item and calc again, it's 2.00, because it still keeps the 1.00 from the first time.

I've tried a few things
1) I've tried setting total = 0 after the calculations
2) I've tried declaring total as a public double but that causes the calculate functions to not work
3) I've tried setting total = 0 in the clear button but I get the error that total is not declared.

Is This A Good Question/Topic? 0
  • +

Replies To: How to reset a price variable?

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1043
  • View blog
  • Posts: 4,060
  • Joined: 02-July 08

Re: How to reset a price variable?

Posted 12 October 2012 - 05:46 PM

What about that subtotal variable?
Was This Post Helpful? 0
  • +
  • -

#3 Varlisk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 20-September 12

Re: How to reset a price variable?

Posted 12 October 2012 - 06:04 PM

View Post_HAWK_, on 12 October 2012 - 05:46 PM, said:

What about that subtotal variable?


Well, I'm supposed to figure out tax, subtotal, and total, but I figure if I can 'clear' one, I can clear the rest the same way, I just cut it down to make the code shorter, but apparently did a less-than-good job of it.
Was This Post Helpful? 0
  • +
  • -

#4 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: How to reset a price variable?

Posted 12 October 2012 - 10:59 PM

Where you describe what you have tried, look again because there is the answer, just do it with all variables involved in calculations. _HAWK_ was pushing you to that direction.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1