I'm currently doing a Point of Sales System but I encountered a problem, the quantity and cost of item add up just fine in the DataGridView but not in the Subtotal, Tax, and Total. I don't know what I did wrong.
Here's my code:
Code:Private Function Cost() As Double Dim sum As Double = 0 Dim i As Integer = 0 For i = 0 To DataGridView1.Rows.Count - 1 sum = sum + Convert.ToDouble(DataGridView1.Rows(i).Cells(2).Value) Next i Return Sum End Function Sub AddCost() Dim vat, q As Double vat = 3.9 If DataGridView1.Rows.Count > 0 Then TxtSub.Text = FormatCurrency(Cost().ToString("0.00")) TxtVAT.Text = FormatCurrency(((Cost() * vat) / 100).ToString("0.00")) q = ((Cost() * vat) / 100) TxtTotal.Text = FormatCurrency(q + Cost().ToString("0.00")) End If End Sub Private Sub BtnTapsi_Click(sender As Object, e As EventArgs) Handles BtnTapsi.Click Dim CostOfItem As Double = 60.0 For Each row As DataGridViewRow In DataGridView1.Rows If row.Cells(0).Value = "Tapsilog" Then row.Cells(1).Value = Double.Parse(row.Cells(1).Value) + 1 row.Cells(2).Value = Double.Parse(row.Cells(1).Value) * CostOfItem Exit Sub End If Next DataGridView1.Rows.Add("Tapsilog", "1", CostOfItem) AddCost() End Sub
And here's a sample image of what the problem looks like:
![]()




Reply With Quote
