vb 这有什么问题?

来源:百度知道 编辑:UC知道 时间:2024/06/04 16:19:15
Private Sub Command1_Click()
Dim a, b, c, d, e, x1, x2 As Single
a = Text1.Text
b = Text2.Text
c = Text3.Text
e = b * b - 4 * a * c
d = spr(d)
If d >= 0 Then
x1 = (-b + d) / (2 * a)
x2 = (-b - d) / (2 * a)
x1 = Text4.Text
x2 = Text5.Text
Else
x1 = "无实数解"
x2 = "无实数解"
x1 = Text4.Text
x2 = Text5.Text
End If

End Sub
说错了
d = spr(d)
是spr(e)

不是spr是sqr,开方!!

Private Sub Command1_Click()
Dim a As Single
Dim b As Single
Dim c As Single
Dim d As Single
Dim x1
Dim x2
a = Text1.Text
b = Text2.Text
c = Text3.Text
d = b * b - 4 * a * c
If d >= 0 Then
x1 = (-b + Sqr(d)) / (2 * a)
x2 = (-b - Sqr(d)) / (2 * a)
Text4.Text = x1
Text5.Text = x2
Else
x1 = "无实数解"
x2 = "无实数解"
Text4.Text = x1
Text5.Text = x2
End If

End Sub

你这样的声明:
Dim a, b, c, d, e, x1, x2 As Single

只有 x2 是 Single 类型,a, b, c, d, e, x1 都是变体类型。

建议改为:
Dim a As Single , b As Single , c As Single , d As Single , e As Single
Dim x1, x2