我有一個關於使用for循環的問題。下面是一個使用數據庫過濾代碼Visual Basic 2008的For循環使用計數器
Private Sub txtsearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearch.KeyDown
On Error Resume Next
If e.KeyCode = Keys.Enter Then
'' Me.Table1BindingSource.Filter = "EmpID = ' " & Me.txtsearch.Text & "'"
On Error Resume Next
Dim temp As Integer = 0
Dim trytime As Integer = 0
Me.Table1BindingSource.Filter = "EmpID = ' " & Me.txtsearch.Text & "'"
For i As Integer = 0 To Table1DataGridView.RowCount - 1
For j As Integer = 0 To Table1DataGridView.ColumnCount - 1
If Table1DataGridView.Rows(i).Cells(j).Value.ToString = txtsearch.Text Then
''if item found then we play sound ok
My.Computer.Audio.Play("F:\beep.wav", AudioPlayMode.WaitToComplete)
My.Computer.Audio.Play("F:\beep.wav", AudioPlayMode.WaitToComplete)
temp = 1
End If
Next
Next
If temp = 0 Then
''if item not found then we play sound err
My.Computer.Audio.Play("F:\computer_access.wav", AudioPlayMode.WaitToComplete)
Me.Table1TableAdapter.Fill(Me.MydbDataSet.Table1)
Me.Table1DataGridView.Refresh()
txtsearch.Text = ""
End If
End If
End Sub
我的問題是,當搜索沒有發現3次,顯示一些MSGBOX
所以放在哪裏trytime循環?
你是什麼意思*三倍*?這個程序會被調用3次,然後你想顯示消息?如果是,那麼變量作用域被錯誤地定義。它應該在這個過程之外,你應該從這個過程中增加它的價值。 – Spidey
我的意思是,如果用戶嘗試三次輸入錯誤的數字,然後** MSGBOX **似乎告訴他,他已經嘗試了3次,並且是真正 –