I'm doing an app and I want to add the values of the column SUBTOTAL classifying it by brand (column MARK ), the problem is that it will vary the brands. In the first instance it only occupied two marks and solved the problem with this code ...
Sub Sumar()
Dim totalA As Double = 0
Dim totalB As Double = 0
For Each fila As DataGridViewRow In dgvDatos.Rows
If fila.Cells("SUBTOTAL").Value Is Nothing Then
Exit Sub
ElseIf fila.Cells("MARCA").Value = "A" Then
totalA += Convert.ToDouble(fila.Cells("SUBTOTAL").Value)
ElseIf fila.Cells("MARCA").Value = "B" Then
totalB += Convert.ToDouble(fila.Cells("SUBTOTAL").Value)
End If
Next
lblA.Text = Format(totalA, "$ #,##0.000")
lblB.Text = Format(totalB, "$ #,##0.000")
End Sub
But now the marks can be variable and just as I am handling it, I would have to declare N variables to store the result by brand. Any suggestions to optimize my operation?
Thanks in advance !!