0

How to check if textbox contains the same barcode of the previous item scaned so that if it does, i will automatically increase quantity something like this:

Dim nextItemBarcode As String = Me.txtBarkodi.Text
Dim quantity As Integer = 1

If Me.txtBarkodi.Text = nextItemBarcode Then
    quantity += 1
Else
    quantity = 1
End If

Do you think I am missing sth or could there be a better algorithm for this scenario?

4

1 回答 1

1

你错过了一些东西。:-)

您需要存储最后一个条码的值,而不是下一个条码。如果新的与上一个相同,则增加数量。如果不相同,则将数量重置为一个并将新条形码存储为最后一个条形码。

Dim lastItemBarcode As String = ""
Dim quantity As Integer

' Scan now. If this is the first bar code,
' quantity will be set to 1 in the Else branch below
' Your scan should work in a loop starting here, so
' it keeps going and doesn't reset lastItemBarcode
' or quantity
If Me.txtBarkodi.Text = lastItemBarcode Then
    ' bar code same as last. Just increase quantity
    quantity += 1
Else
    ' Either the first item scanned, or a different
    ' item. Save this bar code as the current one,
    ' and start our queantity at 1
    lastItemBarcode = me.txtBarkodi.Text
    quantity = 1
End If
于 2013-07-20T16:49:53.450 回答