Results 1 to 9 of 9

Thread: recalculation of totals when items have been removed

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7

    recalculation of totals when items have been removed

    Help!!!! I'm new to VB6 i've removed items from using .removeitems, but now i have to recalcualte the Quantity total and Overall Price total, how do you do this calculation as i can't get them to work properly.

    Can someone please help me!!

  2. #2
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    Need more info...

    What did you remove items from?
    Where are the Quantity and Overall Price stored?
    What is used to calculate them?

    Some code would help.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7
    If you can help that'll be great. Here it goes!!

    Items were removed from list boxes.
    Quantity totals and overall price total is stored in textboxes
    The purchase button is used to calculate them. There is no code in the quantitytotals and overall price totals. they just show the amounts.

    i am trying to recalculate the amounts through the remove button

    Code for purchase/ remove button below

    Private Sub CmdPurchase_Click()
    If txtQuant.Text = "" Then
    MsgBox "Please enter a Quantity", vbExclamation, "Error!"
    Else
    lstItem.AddItem ComboItem.Text
    lstPrice1.AddItem lstprice.Text
    lstQuant1.AddItem txtQuant.Text
    quantity = Val(txtQuant.Text)
    iprice = Val(lstprice.Text)
    lstTotPrice.AddItem quantity * iprice
    totalQuant = totalQuant + Val(txtQuant.Text)
    totalPrice = totalPrice + Str$(Val(lstprice.Text) * Val(txtQuant.Text))
    TxtTotalQuant.Text = totalQuant
    TxtTotalprice2.Text = totalPrice
    txtQuant.Text = ""
    End If

    I've deleted te calculations from the remove button as i got myself inot a tizz

    Private Sub cmdRemove_Click()
    lstItem.RemoveItem lstItem.ListIndex
    lstPrice1.RemoveItem (remItem)
    lstQuant1.RemoveItem (remItem)
    lstTotPrice.RemoveItem (remItem)
    TxtTotalQuant.Text = totalQuant
    TxtTotalprice2.Text = totalPrice
    End Sub

    Thanks alot

  4. #4
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    VB Code:
    1. Private Sub cmdRemove_Click()
    2.     totalQuant = totalQuant - Val(lstQuant1.Text)
    3.     totalPrice = totalPrice - Val(lstPrice1.Text)
    4.     TxtTotalQuant.Text = totalQuant
    5.     TxtTotalprice2.Text = totalPrice
    6.  
    7.     lstItem.RemoveItem lstItem.ListIndex
    8.     lstPrice1.RemoveItem (remItem)
    9.     lstQuant1.RemoveItem (remItem)
    10.     lstTotPrice.RemoveItem (remItem)
    11.     TxtTotalQuant.Text = totalQuant
    12.     TxtTotalprice2.Text = totalPrice
    13. End Sub
    Does this help?

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7
    Thanks John but Nope it doesn't work

    It is clearing the lstboxes but not recaluclating the totals
    Am sending all the code for this form to see if that helps

    Dim Filename As String
    Dim f As Integer
    Dim item As String
    Dim Price As String
    Dim quantity As Integer
    Dim iprice As Currency
    Dim totalQuant As Integer
    Dim totalPrice As Currency


    Private Sub CmdAdd_Click()
    form2.Hide
    Form1.Show
    End Sub

    Private Sub cmdclear_Click()
    If MsgBox("Are you sure you want to clear all these purchases?", vbQuestion + vbOKCancel, "Message Box") = vbOK Then
    lstItem.Clear
    lstItem.SetFocus
    lstPrice1.Clear
    lstQuant1.Clear
    lstTotPrice.Clear
    TxtTotalQuant.Text = "0"
    TxtTotalprice2.Text = "00.00"
    totalQuant = 0
    totalPrice = 0
    End If
    End Sub

    Private Sub CmdPurchase_Click()
    If txtQuant.Text = "" Then
    MsgBox "Please enter a Quantity", vbExclamation, "Error!"
    Else
    lstItem.AddItem ComboItem.Text
    lstPrice1.AddItem lstprice.Text
    lstQuant1.AddItem txtQuant.Text
    quantity = Val(txtQuant.Text)
    iprice = Val(lstprice.Text)
    lstTotPrice.AddItem quantity * iprice
    totalQuant = totalQuant + Val(txtQuant.Text)
    totalPrice = totalPrice + Str$(Val(lstprice.Text) * Val(txtQuant.Text))
    TxtTotalQuant.Text = totalQuant
    TxtTotalprice2.Text = totalPrice
    txtQuant.Text = ""
    End If
    End Sub

    Private Sub cmdQuit_Click()
    If MsgBox("Are you sure you want to Quit?", vbYesNo, "Goodbye") = vbYes Then
    End
    End If
    End Sub


    Private Sub cmdRemove_Click()
    totalQuant = totalQuant - Val(lstQuant1.Text)
    totalPrice = totalPrice - Val(lstPrice1.Text)
    TxtTotalQuant.Text = totalQuant
    TxtTotalprice2.Text = totalPrice

    lstItem.RemoveItem lstItem.ListIndex
    lstPrice1.RemoveItem (remItem)
    lstQuant1.RemoveItem (remItem)
    lstTotPrice.RemoveItem (remItem)
    TxtTotalQuant.Text = totalQuant
    TxtTotalprice2.Text = totalPrice
    End Sub


    Private Sub cmdSearch_Click()
    form2.Hide
    Form3.Show
    End Sub

    Private Sub ComboItem_Click()
    lstprice.ListIndex = ComboItem.ListIndex
    End Sub

    Private Sub Form_Load()
    'open the file
    CommonDialog1.Filter = "all files (*.*)|*.*"
    CommonDialog1.FilterIndex = 2
    CommonDialog1.ShowOpen
    Filename = CommonDialog1.Filename
    f = FreeFile
    Open "A:\Item List.txt" For Input As #f
    'read the file and put in list box

    Do
    Input #f, item, Price
    'print item, price
    ComboItem.AddItem (item)
    lstprice.AddItem (Price)
    'add to list
    Loop Until EOF(f)
    Close #f
    TxtTotalQuant.Text = "0"
    TxtTotalprice2.Text = "00.00"
    End Sub

  6. #6
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Upload the form and i'll fix it for yah. I don't wanna have to make the form myslef and create all those controls and rename em and stuff.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  7. #7
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    I din't have time to go through all the code, but I think this should do it.

    VB Code:
    1. Private Sub cmdRemove_Click()
    2.     totalQuant = totalQuant - Val(lstQuant1.List(lstItem.ListIndex))
    3.     totalPrice = totalPrice - Val(lstPrice1.List(lstItem.ListIndex))
    4.     TxtTotalQuant.Text = totalQuant
    5.     TxtTotalprice2.Text = totalPrice
    6.  
    7.     lstItem.RemoveItem lstItem.ListIndex
    8.     lstPrice1.RemoveItem (remItem)
    9.     lstQuant1.RemoveItem (remItem)
    10.     lstTotPrice.RemoveItem (remItem)
    11.     TxtTotalQuant.Text = totalQuant
    12.     TxtTotalprice2.Text = totalPrice
    13. End Sub
    If not, Arc's suggestion is a good one.

    BTW, I didn't see where you were setting the value of 'remItem', maybe I just missed it. Are you using Option Explicit?

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7
    Thanks John but it still didn't work i tried it that way

    Arc the form won't upload if i get it to work i will send it. thanks for your offer
    K

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    7

    (resolved)recalcualtion ot totals when items have been removed

    Thanks John/Arc

    Got them it to work thanks for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width