|
-
Apr 5th, 2002, 05:04 PM
#1
Thread Starter
New Member
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!!
-
Apr 5th, 2002, 05:08 PM
#2
Frenzied Member
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.
-
Apr 5th, 2002, 05:23 PM
#3
Thread Starter
New Member
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
-
Apr 5th, 2002, 05:34 PM
#4
Frenzied Member
VB Code:
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
Does this help?
-
Apr 5th, 2002, 05:44 PM
#5
Thread Starter
New Member
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
-
Apr 5th, 2002, 05:55 PM
#6
PowerPoster
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.

-
Apr 5th, 2002, 05:58 PM
#7
Frenzied Member
I din't have time to go through all the code, but I think this should do it.
VB Code:
Private Sub cmdRemove_Click()
totalQuant = totalQuant - Val(lstQuant1.List(lstItem.ListIndex))
totalPrice = totalPrice - Val(lstPrice1.List(lstItem.ListIndex))
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
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?
-
Apr 5th, 2002, 07:16 PM
#8
Thread Starter
New Member
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
-
Apr 7th, 2002, 04:02 PM
#9
Thread Starter
New Member
(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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|