pexam5_6.frm

来自「深圳大学的vb上机与教学的课件」· FRM 代码 · 共 136 行

FRM
136
字号
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "求一元二次方程的解"
   ClientHeight    =   2265
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4215
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   14.25
      Charset         =   134
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   ScaleHeight     =   2265
   ScaleWidth      =   4215
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text3 
      Alignment       =   1  'Right Justify
      Height          =   405
      Left            =   2760
      TabIndex        =   2
      Top             =   180
      Width           =   495
   End
   Begin VB.CommandButton Command1 
      Caption         =   "求 解"
      Height          =   375
      Left            =   1320
      TabIndex        =   3
      Top             =   840
      Width           =   1455
   End
   Begin VB.TextBox Text2 
      Alignment       =   1  'Right Justify
      Height          =   405
      Left            =   1800
      TabIndex        =   1
      Top             =   180
      Width           =   495
   End
   Begin VB.TextBox Text1 
      Alignment       =   1  'Right Justify
      Height          =   405
      Left            =   600
      TabIndex        =   0
      Top             =   180
      Width           =   495
   End
   Begin VB.Label Label3 
      Caption         =   "=0"
      Height          =   255
      Left            =   3360
      TabIndex        =   7
      Top             =   255
      Width           =   615
   End
   Begin VB.Label Label4 
      Caption         =   "X+"
      Height          =   255
      Left            =   2400
      TabIndex        =   6
      Top             =   255
      Width           =   495
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "2"
      Height          =   285
      Left            =   1320
      TabIndex        =   5
      Top             =   120
      Width           =   180
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "X +"
      Height          =   285
      Left            =   1200
      TabIndex        =   4
      Top             =   240
      Width           =   735
   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()
  A = Val(Text1.Text)
  B = Val(Text2.Text)
  C = Val(Text3.Text)
  Cls
  CurrentX = 600
  CurrentY = 1300
  If A = 0 Then
    If B = 0 Then
      ' 如果系数A和B为零,则给出提示并选中Text1中的文本
      MsgBox "系数为零,请重新输入"
      Text1.SetFocus
      Text1.SelStart = 0
      Text1.SelLength = Len(Text1.Text)
    Else
      ' 如果系数A为零,B不为零,求出一个解X = -C / B
      X = -C / B
      Print "X="; Format(X, "0.000")
    End If
    Exit Sub
  End If
  ' 如果系数A不为零,根据B^2-4*A*C的不同求解
  Delta = B ^ 2 - 4 * A * C
  Select Case Delta
    Case 0
      Print "X1=X2="; Format(-B / (2 * A), "0.000")
    Case Is > 0
      X1 = (-B + Sqr(Delta)) / (2 * A)
      X2 = (-B - Sqr(Delta)) / (2 * A)
      Print "X1="; Format(X1, "0.000")
      CurrentX = 600
      CurrentY = 1600
      Print "X2="; Format(X2, "0.000")
    Case Is < 0
      A1 = -B / (2 * A)
      A2 = Sqr(Abs(Delta)) / (2 * A)
      Print "X1="; Format(A1, "0.000"); "+"; Format(A2, "0.000"); "i"
      CurrentX = 600
      CurrentY = 1600
      Print "X2="; Format(A1, "0.000"); "-"; Format(A2, "0.000"); "i"
  End Select
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?