3

以下の関数は、質問に対するユーザーの回答を計算することになっています。

ユーザーがテストを受けていない場合は、ユーザーがテストを受けていないというメッセージを表示します。

ユーザーの回答が 0% から 75% の間である場合は、最小要件を満たしていないことをユーザーに知らせます。

ユーザーのスコアが 75% を超える場合、ユーザーは合格です。

問題は、ユーザーのスコアが 0 の場合、ユーザーはテストを受けていないというメッセージが表示され、これが間違っていることです。

これを修正する方法はありますか?

事前にどうもありがとう

Public Function getStatus(ByVal value As Object) As String
    Dim myRow As FormViewRow = scoreGridView.Row
    Dim Message As String = ""
    Dim lbscore As Label = DirectCast(myRow.FindControl("PercentLabel"), Label)
    If Decimal.Parse(value) >= 0 AndAlso Decimal.Parse(value) < 75 Then
        Message = "<span style='color:red;font-weight:bold'>Your score does not meet minimum requirement</span>"
    ElseIf Decimal.Parse(value) >= 75 Then
        Message = "<span style='color:green;font-weight:bold'>Congratulations you have passed the test!</span>"
    Else
        Message = "You have not yet taken the test for this survey"
    End If
    Return Message
End Function
4

2 に答える 2

2

あなたは何を達成しようとしていますか?

コードのベースでは、値が 0 の場合、「スコアが最小要件を満たしていません」が返されます。

値が 0 未満の場合は、「このアンケートのテストはまだ受けていません」を返します。

于 2013-09-12T15:23:40.840 に答える
1

d次のように、値にリテラル サフィックスを使用して、値がDecimal型として比較されるようにします。

Public Function getStatus(ByVal value As Object) As String
    Dim myRow As FormViewRow = scoreGridView.Row
    Dim Message As String = ""
    Dim lbscore As Label = DirectCast(myRow.FindControl("PercentLabel"), Label)
    If Decimal.Parse(value) >= 0d AndAlso Decimal.Parse(value) < 75d Then
        Message = "<span style='color:red;font-weight:bold'>Your score does not meet minimum requirement</span>"
    ElseIf Decimal.Parse(value) >= 75d Then
        Message = "<span style='color:green;font-weight:bold'>Congratulations you have passed the test!</span>"
    Else
        Message = "You have not yet taken the test for this survey"
    End If
    Return Message
End Function

または、ゼロ (10 進数) をチェックするには、次のDecimal.Zeroようにを使用できます。

If Decimal.Parse(value) >= Decimal.Zero AndAlso Decimal.Parse(value) < 75d Then
于 2013-09-12T15:25:19.707 に答える