2012-02-24 12 views
1

ねえみんな私は古いおならです、これは私の最初の投稿ですので、親切にしてください。私は、測定機の基本に基づいて独自の言語で作業しています。最初の2つの小切手はテストの目的で失敗するように慎重に設定しました。サイズXの最初のセットはうまく動作します。コードが実行され、Size_Yに到達すると、オペレーターが「私は再測定したくありません」(7を返します)を選択すると、コードは最後の最後までジャンプします。私は間違って自分の椅子を入れ子にしていると思うが、私はそれを見ることができない。ネストされたif文が他のifsにジャンプする

Private Sub CheckSpec 

'give operator a message if the measure is out of spec 

StartAgain: 

If Size_X <= 3.125 OR Size_X >= 3.125 then 'actual spec 
    'Warn that measure is not in spec and ask for remeasure 

    BoxPick=Msgbox("Measurement in Zone " & Zone & " for Die Size in X is not in spec. Do you want to measure it again?" , 4 , "Measurment NOT Within Tolerance") 
    If BoxPick = 6 THEN 'if operator wants to remeasure, measure again and start checks over 
     Call Measure_Die 
     GoTo StartAgain 
    ElseIF BoxPick <> 7 Then 'If value returned is NOT 6 or 7, throw error 
     OperatorMsg "An error has occured. Contact the tool owner" 
     Call Unload 
    ElseIF BoxPick = 7 Then 'If operator chooses not to remeasure then keep going 
    Else 
    End If 


Elseif Size_Y <= 1.925 OR Size_Y >= 1.925 then 
    'Warn that measure is not in spec and ask for remeasure 

    BoxPick=Msgbox("Measurement in Zone " & Zone & " for Die Size in X is not in spec. Do you want to measure it again?" , 4 , "Measurment NOT Within Tolerance") 
    If BoxPick = 6 THEN 'if operator wants to remeasure, measure again and start checks over 
     Call Measure_Die 
     GoTo StartAgain 
    ElseIF BoxPick <> 7 Then 'If value returned is NOT 6 or 7, throw error 
     OperatorMsg "An error has occured. Contact the tool owner" 
     Call Unload 
    ElseIF BoxPick = 7 Then 'If operator chooses not to remeasure keep going 
    Else 
    End If 


Elseif Centration_X <= 0.175 OR Centration_X >= 0.225 then 

    'Warn that measure is not in spec and ask for remeasure 
    BoxPick=Msgbox("Measurement in Zone " & Zone & " for Die Size in X is not in spec. Do you want to measure it again?" , 4 , "Measurment NOT Within Tolerance") 
    If BoxPick = 6 THEN 'if operator wants to remeasure, measure again and start checks over 
     Call Measure_Die 
     GoTo StartAgain 
    ElseIF BoxPick <> 7 Then 'If value returned is NOT 6 or 7, throw error 
     OperatorMsg "An error has occured. Contact the tool owner" 
     Call Unload 
    ElseIF BoxPick = 7 Then 'If operator chooses not to remeasure keep going 
    Else 
    End If 


Elseif Centration_Y <= 0.95 OR Centration_Y >= 1.0 then 

    'Warn that measure is not in spec and ask for remeasure 
    BoxPick=Msgbox("Measurement in Zone " & Zone & " for Die Size in X is not in spec. Do you want to measure it again?" , 4 , "Measurment NOT Within Tolerance") 
    If BoxPick = 6 THEN 'if operator wants to remeasure, measure again and start checks over 
     Call Measure_Die 
     GoTo StartAgain 
    ElseIF BoxPick <> 7 Then 'If value returned is NOT 6 or 7, throw error 
     OperatorMsg "An error has occured. Contact the tool owner" 
     Call Unload 
    ElseIF BoxPick = 7 Then 'If operator chooses not to remeasure keep going 
    Else 
    End If 
Else 

End If 
Print #1, Column & "," & Row & "," & Level & "," & Zone & "," & Size_X & "," & Size_Y & "," & Centration_X & "," & Centration_Y & "," & RightNow 

End Sub 'CheckSpec 
+2

ようこそstackoverflowへようこそ!私はちょっとフォーマットしました。実際に私にはVisual Basicのように見えます... – MPelletier

答えて

1

あなたは

If (2 + 2 == 4) then 
    do something 
ElseIf (3 + 3 == 6) then 
    code never gets here, even though it is true 
End If 

のような表現はおそらく最速の変化が自分であるためにあなたの主要なのElseIfステートメントを変更することである持っている場合であればブロック

から:

Elseif Size_Y <= 1.925 OR Size_Y >= 1.925 then 

〜へ:

End If 'Size_X block check end 
If Size_Y <= 1.925 OR Size_Y >= 1.925 then 

、その後から:

Elseif Centration_Y <= 0.95 OR Centration_Y >= 1.0 then 

へ:

End If 'Size Y block end 
If Centration_Y <= 0.95 OR Centration_Y >= 1.0 then 
0

あなたはIFの「真」の部品の一つに既にある場合は、ELSEIFブロックの別の部分を入力することはできませんブロック。あなたはすでにブロックの中にいて、残された唯一の場所は最後のEND-IFです。

また、ほとんどの場合、GOTOは処理を行う最良の方法ではありません。次に、あなたのCheckSpec機能は次のようなものになります

Public Enum MeasureResponse 
    StartOver 
    KeepGoing 
    UnloadApp 
End Enum 

Private Function CheckTolerance(ByVal measureValue As Decimal, ByVal lowTolerance As Decimal, ByVal highTolerance As Decimal) As MeasureResponse 
    Dim result As MeasureResponse = MeasureResponse.KeepGoing 

    If measureValue <= lowTolerance Or measureValue >= highTolerance Then 
    Select Case MessageBox.Show("Measurement in Zone Z for Die Size in X is not in spec. Do you want to measure it again?", "Measurement NOT Within Tolerance", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) 
     Case Windows.Forms.DialogResult.Yes 
     Call Measure_Die() 
     result = MeasureResponse.StartOver 
     Case Windows.Forms.DialogResult.Cancel 
     result = MeasureResponse.UnloadApp 
    End Select 
    End If 

    Return result 
End Function 

を::

は、必要に応じて、このような何か、リファクタリングを考えてみましょう。これは、VB.Netである

Private Sub CheckSpec() 
    For i As Integer = 1 To 4 
    Dim checkItem As Decimal = Choose(i, size_X, size_Y, centration_X, centration_Y) 
    Dim lowTolerance As Decimal = Choose(i, 3.125, 1.925, 0.175, 0.95) 
    Dim highTolerance As Decimal = Choose(i, 3.125, 1.925, 0.225, 1.0) 

    Select Case CheckTolerance(checkItem, lowTolerance, highTolerance) 
     Case MeasureResponse.StartOver 
     i = 0 
     Case MeasureResponse.UnloadApp 
     Exit Sub 
    End Select 
    Next 

    Print #1, Column & "," & Row & "," & Level & "," & Zone & "," & Size_X & "," & Size_Y & "," & Centration_X & "," & Centration_Y & "," & RightNow 
End Sub 

を、それはに翻訳可能でなければなりませんVB6またはこの基本言語があなたが使用しているものであれば、

使用している許容誤差の例でも意味がありません。 Size_X <= 3.125 OR Size_X >= 3.125は毎回真実になるでしょう。私はそれがテスト目的のためだと仮定します。

関連する問題