显示基于分数的排名

时间:2014-10-24 13:54:14

标签: .net vb.net if-statement ranking scoring

我一直试图让这些代码工作,但没有运气。我试图根据“差点”得分打印一定等级,但它似乎只是随机打印一个等级。我有代码成功地计算了差点,但是一旦我得到我的if语句试图打印分数,它似乎只是随机打印文本。

            If (Handicap < 0) Then
                TxtRank.Text = "Championship"
            ElseIf (0 > Handicap Or Handicap < 5) Then
                TxtRank.Text = "Duffer"
            ElseIf (5 < Handicap Or Handicap < 10) Then
                TxtRank.Text = "Average"
            ElseIf (Handicap > 10) Then
                TxtRank.Text = "Hacker"
            End If

2 个答案:

答案 0 :(得分:2)

当像这样测试多个值的变量时,使用Select Case语句会更容易。

您遇到问题的原因是您没有满足所有可能的值,并且您的逻辑与某些值存在冲突,例如0 > Handicap Or Handicap < 5

    Select Case Handicap
        Case Is < 0
            TxtRank.Text = "Championship"
        Case Is < 5
            TxtRank.Text = "Duffer"
        Case Is < 10
            TxtRank.Text = "Average"
        Case Else
            TxtRank.Text = "Hacker"
    End Select

答案 1 :(得分:1)

你有太多无用的选项让人难以阅读。试试这个:

        If (Handicap < 0) Then
            TxtRank.Text = "Championship"
        ElseIf Handicap < 5 Then
            TxtRank.Text = "Duffer"
        ElseIf Handicap < 10 Then
            TxtRank.Text = "Average"
        Else
            TxtRank.Text = "Hacker"
        End If