VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3555
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4710
   LinkTopic       =   "Form1"
   ScaleHeight     =   3555
   ScaleWidth      =   4710
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "求  根"
      Height          =   375
      Left            =   1680
      TabIndex        =   8
      Top             =   1440
      Width           =   975
   End
   Begin VB.TextBox Text3 
      Height          =   375
      Left            =   3360
      TabIndex        =   6
      Top             =   840
      Width           =   495
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   2160
      TabIndex        =   5
      Top             =   840
      Width           =   495
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   840
      TabIndex        =   4
      Top             =   840
      Width           =   495
   End
   Begin VB.Label Label5 
      Caption         =   "Label5"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1335
      Left            =   240
      TabIndex        =   7
      Top             =   2040
      Width           =   4455
   End
   Begin VB.Label Label4 
      Caption         =   "b="
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   1680
      TabIndex        =   3
      Top             =   840
      Width           =   375
   End
   Begin VB.Label Label3 
      Caption         =   "c="
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   2880
      TabIndex        =   2
      Top             =   840
      Width           =   375
   End
   Begin VB.Label Label2 
      Caption         =   "a="
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   360
      TabIndex        =   1
      Top             =   840
      Width           =   375
   End
   Begin VB.Label Label1 
      Caption         =   "求一元二次方程的根"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   720
      TabIndex        =   0
      Top             =   240
      Width           =   3015
   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 Integer, b As Integer, c As Integer, x1 As Single, x2 As Single
    Dim strLab As String
    a = Val(Text1.Text)
    b = Val(Text2.Text)
    c = Val(Text3.Text)
    Select Case FunD(a, b, c)               '使用函数FunD返回值为分支条件，判断是否有根
        Case Is < 0
            strLab = "该方程无根！"
        Case Is = 0
            x1 = (-b) / (2 * a)                             '求方程的根
            strLab = "该方程有一个实数根:" + Chr(13) + "  x1 = " + Str(x1)
        Case Is > 0
            x1 = (-b + Sqr(FunD(a, b, c))) / (2 * a)        '求方程的根
            x2 = (-b - Sqr(FunD(a, b, c))) / (2 * a)        '求方程的根
            strLab = "该方程有两个不同实数根:" + Chr(13) + " x1=" + Str(x1) + "  x2=" + Str(x2)
    End Select
    Label5.Caption = strLab
End Sub
Rem 自定义函数过程用于求证方程是否有根
Private Function FunD(a As Integer, b As Integer, c As Integer)
    FunD = b * b - 4 * a * c           '设置函数返回值
End Function

