Hi everyone, I'm stuck on how to calculate the item price for every checked Item. This function user can check multiple item and the subtotal will automatically calculated.
Private Sub CheckBox1_CheckedChange(Checked As Boolean)
Dim cb As String
Dim totalSelected As Int
Dim chk As CheckBox = Sender.As(CheckBox)
Dim itemC() As String = Regex.Split("\|", chk.Tag)
If itemC.Length > 1 Or Checked == True Then
chk.Tag = itemC(0)
Return
End If
If Checked = True Then
cb="1"
lblDashOrderSubTotal.Text = lblDashOrderSubTotal.Text + priceItem
Else
cb="0"
End If
End Sub
Also, the obvious, if the Item is checked and then you UNCHECK it, you now need to Subtract the value (Using the above approach). There seem to be no quantities in the above example, but if you introduce a quantity as well, then you have a more complex problem to solve.
If you are checking a checkbox where you have only a very few items, then I would do a recalculation, of ALL the checked items, every time a checkbox is checked (or unchecked) - In this way you don't have a lot of decisions to make to arrive at a total, even with a quantity involved. (Hundreds of items in a list to pick from will not slow your program noticeably).
If on the other hand, you are dealing with a huge list (thousands of items) that could be checked or unchecked, I would create a separate list for the sale which would consist of the Item Code, Price and Quantity. Then if you check an item, you add it to the list, or remove it from the list if the item is unchecked - You would then cycle through the list to arrive at a total of checked items and quantities. (Presumably you are trying to calculate a value so that it can be displayed on the screen).
When you actually complete your list of checked items (ie, End of Sale), you may like to display the list of checked items on screen with totals etc.
Then you may need to make another series of calculations which may or may not include Taxes, Freight, etc, and possibly committing the quantities bought to reduce Stock on Hand, etc. when the Sale is finally committed.