错误结束语句预期

时间:2014-12-01 05:21:49

标签: vb.net

我创建了一个按钮,但收到Error End of statement expected错误。

这是我的代码:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

X = TextBox1.Text
Y = TextBox2.Text

If RadioButton1.Checked = True Then Z = X + Y  End IF

If RadioButton2.Checked = True Then Z = X - Y End IF

If RadioButton3.Checked = True Then Z = X * Y End IF

If RadioButton4.Checked = True Then Z = X / Y End IF

TextBox3.Text = Z

2 个答案:

答案 0 :(得分:1)

编写单行If 语句时,您不必放End If
这就是为什么它抱怨End of statement expected.

答案 1 :(得分:-1)

您的代码似乎没有任何问题(只要在IDE中格式正确;问题中的格式错误)。

为了好玩,我为你换了一些东西。您可以尝试这样的方法来使代码更具可读性:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    X = CDbl(TextBox1.Text)
    Y = CDbl(TextBox2.Text)
    Select Case True
        Case RadioButton1.Checked
            TextBox3.Text = X + Y
        Case RadioButton2.Checked
            TextBox3.Text = X - Y
        Case RadioButton3.Checked
            TextBox3.Text = X * Y
        Case RadioButton4.Checked
            TextBox3.Text = X / Y
    End Select