VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "求解一元二次方程"
   ClientHeight    =   5715
   ClientLeft      =   120
   ClientTop       =   450
   ClientWidth     =   8280
   LinkTopic       =   "Form1"
   ScaleHeight     =   5715
   ScaleWidth      =   8280
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "求解方程"
      Height          =   615
      Left            =   1080
      TabIndex        =   6
      Top             =   4680
      Width           =   1575
   End
   Begin VB.TextBox Text3 
      Height          =   615
      Left            =   1680
      TabIndex        =   5
      Top             =   2880
      Width           =   1335
   End
   Begin VB.TextBox Text2 
      Height          =   615
      Left            =   1680
      TabIndex        =   4
      Top             =   1800
      Width           =   1335
   End
   Begin VB.TextBox Text1 
      Height          =   615
      Left            =   1680
      TabIndex        =   3
      Top             =   720
      Width           =   1335
   End
   Begin VB.Label Label5 
      Height          =   735
      Left            =   4440
      TabIndex        =   8
      Top             =   1560
      Width           =   1575
   End
   Begin VB.Label Label4 
      Caption         =   "求解结果："
      Height          =   255
      Left            =   4440
      TabIndex        =   7
      Top             =   840
      Width           =   1215
   End
   Begin VB.Label Label3 
      Caption         =   "c："
      Height          =   375
      Left            =   960
      TabIndex        =   2
      Top             =   2880
      Width           =   495
   End
   Begin VB.Label Label2 
      Caption         =   "b："
      Height          =   375
      Left            =   960
      TabIndex        =   1
      Top             =   1920
      Width           =   495
   End
   Begin VB.Label Label1 
      Caption         =   "a："
      Height          =   375
      Left            =   960
      TabIndex        =   0
      Top             =   840
      Width           =   495
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single, d As Single
Dim x1 As Double, x2 As Double
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a <> 0 Then
d = b ^ 2 - 4 * a * c
If d > 0 Then
x1 = (-b + Sqr(d)) / (2 * a)
x2 = (-b - Sqr(d)) / (2 * a)
Label5.Caption = "x1=" & Str(x1) & Chr(10) & "x2=" & Str(x2)
Else
Label5.Caption = "方程没有实数解"
End If
Else
If a = 0 Then
If b = 0 Then
MsgBox "系数为零，请重新输入"
Else
x1 = -c / b
Label5.Caption = "x1=" & Str(x1)
End If
End If
End If

End Sub
