这个我直接用的4个command控件,如果你学过应该能看懂
Dim a As Integer, b As Integer, c As Integer
Private Sub Command1_Click()
a = InputBox("请输入二次项系数", "输入")
End Sub
Private Sub Command2_Click()
b = InputBox("请输入一次项系数", "输入")
End Sub
Private Sub Command3_Click()
c = InputBox("请输入常数项", "输入")
End Sub
Private Sub Command4_Click()
If b ^ 2 - 4 * a * c >= 0 Then
If b ^ 2 - 4 * a * c > 0 Then
X1 = (-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
X2 = (-b - Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
MsgBox "x1=" & Format(X1, "#0.00") & vbCrLf & "x2=" & Format(X2, "#0.00")
End If
If b ^ 2 - 4 * a * c = 0 Then
X1 = (-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
MsgBox "x1=" & Format(X1, "#0.00")
End If
Else
d = (-b / (2 * a))
s = Sqr(-b ^ 2 + 4 * a * c)
MsgBox "x1=" & Format(d, "#0.00") & "+" & Format(s, "#0.0") & "i" & Chr(13) & "x2=" & Format(d, "#0.00") & "-" & Format(s, "#0.0") & "i"
End If
End Sub
© 2017-2019 超级试练试题库,All Rights Reserved.