2013-10-23 48 views
0

我真的很惱火在這裏。我不明白爲什麼這個事件不斷拋出一個空白的錯誤。以下是我的代碼。VB.Net SelectedChangeCommitted拋出錯誤

Private Sub cboSections_SelectedChangeCommitted(sender As System.Object, e As System.EventArgs) Handles cboSections.SelectionChangeCommitted 
    On Error GoTo EH 

    If TypeOf sender Is Windows.Forms.ComboBox Then 
     'some boolean that checks if we are skipping this event, thus it does if so 
     If mbSkipEvent Then Exit Sub 

     'checks if index that was changed to is > 0 then it toggles the bottom command buttons 
     If cboSections.SelectedIndex > 0 Then 
      ToggleCmdButtons(True) 
     Else 
      ToggleCmdButtons(False) 
     End If 

     'sets the string msPurpose 
     msPurpose = "Show Section" 
     Debug.Print("Im here") 
    End If 
EH: 
    Debug.Print("Error Description: " & Err.Description) 
End Sub 

在我的輸出中,我得到「錯誤描述:」。而已。如果任何人有任何解決方案或指向正確的方向將是偉大的。

+0

On Error Goto?請救我。 –

+0

我想這是不好的做法... – j0hnstew

回答

1

讓我們嘗試一些真正的錯誤處理,看看你是否有更好的。雖然我們在這,但我們可以簡化代碼:

Private Sub cboSections_SelectedChangeCommitted(sender As System.Object, e As System.EventArgs) Handles cboSections.SelectionChangeCommitted 
    Dim comboBox = TryCast(sender, ComboBox) 
    If comboBox Is Nothing OrElse mbSkipEvent Then Exit Sub 
    Try 
     'checks if index that was changed to is > 0 then it toggles the bottom command buttons 
     ToggleCmdButtons(cboSections.SelectedIndex > 0) 

     'sets the string msPurpose 
     msPurpose = "Show Section" 
     Debug.Print("Im here") 
    Catch Ex As Exception 
     Debug.Print("Error Description: " & Ex.Message) 
    End Try 
End Sub 
+0

不知道究竟是什麼修復它。但是現在我沒有錯誤。 – j0hnstew