2012-04-07 2 views
0

문자를 입력했거나 번호가 울린 상태에서 예외를 잡으려면이 코드 줄을 사용해야하지만 숫자 데이터를 포착하지 않으려면 WHEN을 추가하십시오. 이제는 예외 오류를 사용하여 코드를 두 번 실행하지 않으려면 사례 문 앞에 사용하십시오. 사례 코드가 실행되면 이미 try catch에 의해 처리 된 명확한 txtbox가 실행됩니다. 그게 당신에게 명확하지만, 나는 그것을 이해합니다. 여기 부분의 코드입니다 ... 내가 할 싶은 것이코드를 두 번 실행하지 않으려면 이전 시도 잡기 예외를 사용합니까?

Try 
     'Integer Levels: intLvls is egual to the assigned text box, the first one from 
     'the top, this line of code allow the user input to be captured into a variable. 
     intLvls = txtBoxLvl.Text 
    Catch ex As Exception When IsNumeric(intLvls) 
     ErrTypeLetterFeild1() 
    Finally 
     analysingvalues1() 
    End Try 

: 사용 루프를 예외 오류를 refencing 때까지 코드의 다음 부분을 실행하지 않도록 :

Private Sub analysingvalues1() 
    Do Until IsNumeric (ex As Exception)<------how do i do this??? 

    Loop 

경우 부분 코드의 :

Select Case intLvls 
     'User is prompt with the following label: lblLvl "Level of salespersons 1 - 4" 
     'to make a choice from 1 to 4 as available values. 
     Case 1 To 4 
      'This line regulates the range of acceptable values, first textbox: must be egual 
      'or higher than 1 and lower or egual to 4. Upon such rules a validation becomes 
      'correct and is directed to the isValidCalculation sub. 
      isValidCalculation() 
     Case Is < 1 
      ErrType1NumberRangeFeild() 
     Case Is > 4 
      ErrType1NumberRangeFeild() 
     Case Else 
      If txtBoxLvl.Text = "" Then 
       ErrTypeClear1() 
      Else 
       If Not IsNumeric(txtBoxLvl.Text) Then 
        ErrType1NumberRangeFeild() 
       Else 
        ErrTypeLetterFeild1() 
        ErrTypeClear1() 
       End If 
      End If 
    End Select 'Ending choices. 
End Sub 

당신의 도움을위한 Tks! 이 엄격한 옵션을 설정하면

+0

'Option Strict On'을 코드 맨 위에 올리거나 프로젝트 속성에서 설정하십시오. intLvls의 유형은 무엇입니까? –

답변

3

:

intLvls = txtBoxLvl.Text 

는 더 이상 컴파일되지 않습니다. 이것은 당신이 뭔가 냄새 나는 것을 말해야합니다.

올바른 솔루션 엄격한 옵션에

켭니다 맹목적으로 런타임 당신을 위해 INT, 그리고 예외를 잡을 수있는 문자열을 캐스팅 할 수 있도록하지 않습니다.

문자열 사용자 입력을 정수로 변환 할 때 잘못된 입력이 이 아닌이 아닌 예외적 인 조건이므로 예상하고 코딩해야하는 내용입니다.

나는 이런 식으로 다시 것 :

'Integer Levels: intLvls is egual to the assigned text box, the first one from 
    'the top, this line of code allow the user input to be captured into a variable. 

    if integer.TryParse(txtBoxLvl.Text, intLvls) 
     analysingvalues1() 
    else 
     ErrTypeLetterFeild1() 

편집 - 아래 크리스가 지적한 바와 같이, 내가 엄격한 옵션을 의미했다. 나는 Explicit and Strict와 Infer를 사용할 것을 권장한다.

+0

나는 Option Strict를 의미한다고 생각하니? –

+0

@ChrisDunaway Woops, 당신은 정확합니다! – asawyer

관련 문제