为什么我的病情没有按预期工作?

时间:2014-03-04 14:14:29

标签: vb.net

我的病情没有效果是什么问题?有谁可以帮助我?

Public Class Form5

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim a As Integer
        If TextBox1.Text = "" Then
            TextBox2.Text = ""
        End If

        a = Val(TextBox1.Text)
        If TextBox1.Text = "" Then
            TextBox2.Text = ""
        ElseIf (a < 4.9) Then
            TextBox2.Text = ("Little or No Damage")
        ElseIf (a <= 5 AndAlso a >= 5.5) Then
            TextBox2.Text = ("Some Damage")
        ElseIf (a <= 5.6 And a >= 6.5) Then
            TextBox2.Text = ("Serious Damage")
        ElseIf (a <= 6.6 And a >= 7.5) Then
            TextBox2.Text = ("Disaster")
        ElseIf (a > 7.5) Then
            TextBox2.Text = ("Catasthrope")
        End If

    End Sub
End Class

1 个答案:

答案 0 :(得分:3)

您刚刚混淆了<=>=

但是如果你使用Select代替它会更具可读性且不易出错,例如:

Select Case a
    Case Is < 4.9
        TextBox2.Text= "Little or No Damage"
    Case 5 To 5.5
        TextBox2.Text= "Some Damage"
    Case 5.6 To 6.5
        TextBox2.Text= "Serious Damage"
    Case 6.6 To 7.5
        TextBox2.Text= "Disaster"
    Case Is > 7.5
        TextBox2.Text= "Catasthrope"
End Select