2015-05-06 114 views
0

您好,我正在嘗試掃描一個二維碼。然後檢查代碼或值是否在DataGridView中。如果發現我需要一個msgbox讓我知道它已經被掃描。如果不是繼續將其輸入到DataGrid並停止或某種延遲,以便有時間更改qr代碼。掃描二維碼添加到DataGridView和停止如果價值已經存在

我已經掃描的代碼,但我得到了msgbox的循環,並必須覆蓋相機停止「垃圾郵件」msgboxes。我相信我的代碼錯誤可能會給我任何幫助?

這就是我需要的。 掃描 - >數據網格中的值(如果否,則添加到數據網格和延遲)(如果是MsgBox「已在系統中」延遲重新開始)。

我的代碼:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 
     If VideoSourcePlayer1.GetCurrentVideoFrame() IsNot Nothing Then 
      Dim img As New Bitmap(VideoSourcePlayer1.GetCurrentVideoFrame) 
      Dim results As String() = BarcodeReader.read(img, BarcodeReader.QRCODE) 
      img.Dispose() 
      If results IsNot Nothing AndAlso results.Count > 0 Then 
       If results(0).IndexOf("event") <> -1 Then 
        'Remove verification code and post to listbox 
        results(0) = results(0).Replace("event", "") 
        Dim code As String = results(0) 
        Try 
         If DataGridView2.Rows.Count >= 0 Then 
          For i As Integer = 0 To DataGridView2.Rows.Count - 1 
           Dim CellChange As String = DataGridView2.Rows(i).Cells("CODE").Value.ToString 
           If CellChange.Contains(results(0)) = True Then 
            Timer1.Stop() 
            MsgBox("Ticket already in system") 
            If MsgBoxResult.Ok Then 
             Timer1.Start() 
            End If 
           Else 
            Timer1.Stop() 
            DataGridView2.Rows.Add(code) 
            Timer1.Start() 
           End If 
          Next 
         End If 
        Catch ex As Exception 
         MessageBox.Show(e.ToString()) 
        End Try 
       End If 
      End If 
     End If 
    End Sub 

回答

0

循環正在發生的事情,因爲你確認消息框後,你再次激活定時器,這將導致相同的代碼全部重新執行。您應該刪除或重新考慮這段代碼的位置:

If MsgBoxResult.Ok Then 
    Timer1.Start() 
End If 

或者,你可以在最後一次掃描代碼存儲在一個變量,然後掃描新代碼後,比較兩個。如果新代碼與舊代碼相符,Exit Sub並等待下一個打勾。

相關問題