如何修复“未定义操作员”错误VB

时间:2019-05-10 06:26:49

标签: vb.net winforms

为类中的项目编写“平均计算器”的代码,但我不断收到消息“ BC30452运算符'> ='未为类型'Label'和'Integer'定义。其他运算符也使用了'<< ='

我是一个初学者,对自己的工作感到迷恋。

Private Sub btnCalcAvg_Click(sender As Object, e As EventArgs)Handles btnCalcAvg.Click
    Dim label1 As Integer
    Dim label2 As Integer
    Dim label3 As Integer

    label1 = txtTest1.Text
    label2 = txtTest2.Text
    label3 = txtTest3.Text

    lblAverage.Text = (txtTest1.Text + txtTest2.Text + txtTest3.Text) / 3

    lblAverage.Text = lblAverage.ToString

End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
    txtTest1.Text = String.Empty
    txtTest2.Text = String.Empty
    txtTest3.Text = String.Empty
    lblAverage.Text = String.Empty

End Sub

Private Sub lblGrade_Click(sender As Object, e As EventArgs) Handles lblGrade.Click
    If (lblAverage >= 90) Then lblGrade.Text = "A"
    If (lblAverage <= 89) Then lblGrade.Text = "B"
    If (lblAverage <= 79) Then lblGrade.Text = "C"
    If (lblAverage <= 69) Then lblGrade.Text = "D"
    If (lblAverage <= 59) Then lblGrade.Text = "F"
End Sub

这是我正在使用的程序图片的link,有助于使我更清楚地了解要实现的目标。

还有一个图例,可用于在需要的情况下引用名称:

标签1,文字:Test1;名称:空白

标签2,文字:Test2;名称:空白

Label3,文字:Test3;名称:空白

标签4,文字:平均值;名称:空白

标签5,文字:等级;名称:空白

标签6,文本:空白;名称:lblAverage

Label7,文字:空白;名称:lblGrade

Textbox1,测试:空白;名称:txtTest1

Textbox2,测试:空白;名称:txtTest2

Textbox3,测试:空白;名称:txtTest3

按钮1,文字:计算平均值;名称:btnCalcAvg

Button2,文本:清除;名称:btnClear

0 个答案:

没有答案