vb的一元二次方程解法为什么错误?

来源:百度知道 编辑:UC知道 时间:2024/05/17 00:51:12
Private Sub Command1_Click()
Dim a, b, c As Single
Dim delta As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
delta = b * b - 4 * a * c
If a = 0 Then
Text4.Text = "非一元二次方程"
ElseIf delta < 0 Then
Text4.Text = "此方程无解"
ElseIf delta = 0 Then
Text4.Text = "此方程有两相同实数根"
Text5.Text = Str(-b / 2 * a)
Text6.Text = Str(-b / 2 * a)
ElseIf delta > 0 Then
Text4.Text = "此方程有两不同实数根"
Text5.Text = Str((-b + Sqr(delta)) / 2 * a)
Text6.Text = Str((-b - Sqr(delta)) / 2 * a)
End If
End Sub

以上是我写的程序
请大侠们看看
提示的是 编译错误:未找到方法或数据成员

Text5.Text = Str(-b / 2 * a)
Text6.Text = Str(-b / 2 * a)
Text5.Text = Str((-b + Sqr(delta)) / 2 * a)
Text6.Text = Str((-b - Sqr(delta)) / 2 * a)
上面的运算中/号和*号的运算级别是同级别,因此运算是首先运算-b/2,结果在*2,因此结果必然错误,但这不是你的问题的答案,在这里提醒你。

你的问题我考虑是文本框的名称错误!例如Text5应该不是Text5,请仔细检查。我运行了你的程序,程序没有错误,但是答案不正确。

Dim a As Single, b As Single ,c As Single

测试未见你所说的错误.

Dim a, b, c As Single

这样 a 和 b都为变体型了。 要分开定义