0

テキストボックスにスキャンされた前のアイテムと同じバーコードが含まれているかどうかを確認する方法。含まれている場合は、次のように数量を自動的に増やします。

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

私が sth を見逃していると思いますか、それともこのシナリオのためのより良いアルゴリズムがあると思いますか?

4

1 に答える 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 に答える