3

The function below is supposed to calculate user's answers to questions.

If the user hasn't take the test, show a message that the user hasn't taken the test.

If the user's answer is between 0% and 75%, let the user know s/he doesn't meet minimum requirement.

If the user's score is greater than 75%, then user has passed.

Problem is that if the user's score is 0, then user gets a message that s/he hasn't taken the test and this wrong.

Any idea how I can correct this?

Thanks a lot in advance

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

或者,为了检查零(十进制),您可以使用Decimal.Zero,如下所示:

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