VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "计算器"
   ClientHeight    =   2220
   ClientLeft      =   1095
   ClientTop       =   1515
   ClientWidth     =   4335
   BeginProperty Font 
      Name            =   "MS Sans Serif"
      Size            =   12
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   2220
   ScaleWidth      =   4335
   Begin VB.CommandButton Command2 
      Caption         =   "结束"
      Height          =   495
      Left            =   2400
      TabIndex        =   9
      Top             =   1560
      Width           =   855
   End
   Begin VB.TextBox Text1 
      Height          =   420
      Left            =   240
      TabIndex        =   0
      Text            =   " "
      Top             =   240
      Width           =   975
   End
   Begin VB.TextBox Text5 
      Height          =   420
      Left            =   2520
      TabIndex        =   5
      Text            =   " "
      Top             =   840
      Width           =   1455
   End
   Begin VB.CommandButton Command1 
      Caption         =   "计算"
      Height          =   495
      Left            =   840
      TabIndex        =   4
      Top             =   1560
      Width           =   855
   End
   Begin VB.TextBox Text4 
      Height          =   420
      Left            =   600
      TabIndex        =   3
      Text            =   " "
      Top             =   840
      Width           =   1455
   End
   Begin VB.TextBox Text3 
      Height          =   420
      Left            =   2880
      TabIndex        =   2
      Top             =   240
      Width           =   975
   End
   Begin VB.TextBox Text2 
      Height          =   420
      Left            =   1440
      TabIndex        =   1
      Text            =   " "
      Top             =   240
      Width           =   1095
   End
   Begin VB.Label Label3 
      Caption         =   "a                b                   c"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   360
      TabIndex        =   8
      Top             =   0
      Width           =   3855
   End
   Begin VB.Label Label2 
      Caption         =   "x2="
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2040
      TabIndex        =   7
      Top             =   840
      Width           =   615
   End
   Begin VB.Label Label1 
      Caption         =   "x1="
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   6
      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
Dim a#, b#, c#, x1#, x2#

Private Sub Form_Click()
  Dim dalt!
  a = InputBox("输入系数a")
  b = InputBox("输入系数b")
  c = InputBox("输入系数c")
  dalt = b * b - 4 * a * c
  If dalt > 0 Then                        '两个实根
      dalt = Sqr(dalt)
      Print "两个实根："; Format((-b + dalt) / 2 / a, "; 0#; "), Format((-b - dalt) / 2 / a, "; 0#; "); ""
  ElseIf dalt = 0 Then                    '重根
      Print "重根："; Format(-b / 2 / a, "0.00")
  Else
      dalt = Sqr(-dalt)                   '复根
      Print "复根："; Format(-b / 2 / a, "0.00"); "+i"; Format(dalt / 2 / a, "0.00")
      Print "       "; Format(-b / 2 / a, "0.00"); "-i"; Format(dalt / 2 / a, "0.00")
  End If
End Sub
'
Private Sub Text1_LostFocus()
  If Not IsNumeric(Text1) Then    '输入数据不是为数字
    Text1 = ""                    '清除文本框
    Text1.SetFocus                '焦点回到该文本框
  Else
    a = Text1                     '输入正确,同时放入变量a中,为计算时使用
  End If
End Sub
Private Sub Text2_LostFocus()     '当该框内输入过内容,且内容为非数字
  If Text2 <> "" And Not IsNumeric(Text2) Then
    Text2 = ""
    Text2.SetFocus
  Else
    b = Text2
  End If
End Sub
Private Sub Text3_LostFocus()
  If Text3 <> "" And Not IsNumeric(Text3) Then
    Text3 = ""
    Text3.SetFocus
  Else
    c = Text3
  End If
End Sub
Private Sub Command1_Click()
   Dim dalt!
   dalt = b * b - 4 * a * c
   If dalt > 0 Then                        '两个实根
      dalt = Sqr(dalt)
      Text4 = Format((-b + dalt) / 2 / a, "0.00")
      Text5 = Format((-b - dalt) / 2 / a, "0.00")
   ElseIf dalt = 0 Then                    '重根
      Text4 = Format(-b / 2 / a, "0.00")
      Text5 = Format(-b / 2 / a, "0.00")
   Else
      dalt = Sqr(-dalt)                    '复根
      Text4 = Format(-b / 2 / a, "0.00") & "+" & Format(dalt / 2 / a, "0.00") & "i"
      Text5 = Format(-b / 2 / a, "0.00") & "-" & Format(dalt / 2 / a, "0.00") & "i"
   End If
End Sub


