-2

Windowsフォームのビジュアルベーシックでプログラムを実行しており、複数のカウンターを作成しようとしています

これが私のコードです:

If txtAnswer.Text = nMathSum Then
        nCount = nCount + 1
        lblCorrect.Text = nCount
    ElseIf txtAnswer.Text <> nMathSum Then
        nIount = nIount + 1
        lblIncorrect.Text = nIount
    End If

    If txtAnswer.Text = nMathDiff Then
        nCount = nCount + 1
        lblCorrect.Text = nCount
    ElseIf txtAnswer.Text <> nMathDiff Then
        nIcount = nIcount + 1
        lblIncorrect.Text = nIout
    End If

正解と不正解の回数をカウントするとします

合計のカウンターは正常に機能していますが、差額のカウンターに問題があります。正しい答えを入力すると、間違ったラベルに移動します。

4

2 に答える 2

0

txtAnswer が合計と差の両方に一致する可能性はほとんどありません。そのため、コードでは常に少なくとも 1 つが正しくありません。

txtAnswer が合計または差と一致するかどうかを知る方法はありますか?もしそうなら、答えを確認する前に確認してください。

編集(私が何を意味するかを説明するため):次のようなもの

If operation = "+" Then
    If txtAnswer.Text = nMathSum Then
        nCount = nCount + 1
        lblCorrect.Text = nCount
    ElseIf txtAnswer.Text <> nMathSum Then
        nIcount = nIcount + 1       ' corrected this line to use nIcount
        lblIncorrect.Text = nIcount ' corrected this line to use nIcount
    End If
Else
    If txtAnswer.Text = nMathDiff Then
        nCount = nCount + 1
        lblCorrect.Text = nCount
    ElseIf txtAnswer.Text <> nMathDiff Then
        nIcount = nIcount + 1
        lblIncorrect.Text = nIcount ' corrected this line too
    End If
End If

ここで、操作は、ユーザーが合計または差を提供することになっているかどうかに応じて、「+」または「-」に設定される変数です。

于 2012-04-06T16:43:07.667 に答える
0

最後の行の ように、seconfのnIountasのスペルミスがあります。次のように修正します。nIcountElseifnIout

ElseIf txtAnswer.Text <> nMathDiff Then 
    nIount = nIount + 1 
    lblIncorrect.Text = nIount 
End If 

これは、初出 ( nIount) が正しいスペルであると想定しています。

于 2012-04-06T16:45:53.497 に答える