Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
Dim d As Single, x1 As Single, x2 As Single
Dim r As Single, p As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a = 0 Then
Text4.Text = "一元二次方程的系数A不能为0"
Text5.Text = "一元二次方程的系数A不能为0"
Else
d = b ^ 2 - 4 * a * c
r = -b / (2 * a)
If d = 0 Then
Text4.Text = r
Text5.Text = r
ElseIf d > 0 Then
x1 = (-b + Sqr(d)) / (2 * a)
x2 = (-b - Sqr(d)) / (2 * a)
Text4.Text = x1
Text5.Text = x2
ElseIf d < 0 Then
p = Sqr(-d) / 2 * a
Text4.Text = r & "+" & p & "i"
Text5.Text = r & "-" & p & "i"
End If
End If
End Sub