2013-10-23 2 views
0

나는 정말 여기에 화가났다. 나는 왜이 사건이 공백의 오류를 던지는지 이해하지 못한다. 아래는 제 코드입니다.VB.Net SelectedChangeCommitted Throwing Error

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