解方程.vb

来自「Visual Basic .NET程序设计教程源代码」· VB 代码 · 共 136 行

VB
136
字号
Imports System.Math

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写处置以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents a5 As System.Windows.Forms.TextBox
    Friend WithEvents a4 As System.Windows.Forms.TextBox
    Friend WithEvents a1 As System.Windows.Forms.TextBox
    Friend WithEvents a2 As System.Windows.Forms.TextBox
    Friend WithEvents a3 As System.Windows.Forms.TextBox
    Friend WithEvents b1 As System.Windows.Forms.Button
    Friend WithEvents b2 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.a5 = New System.Windows.Forms.TextBox()
        Me.a4 = New System.Windows.Forms.TextBox()
        Me.a1 = New System.Windows.Forms.TextBox()
        Me.a2 = New System.Windows.Forms.TextBox()
        Me.a3 = New System.Windows.Forms.TextBox()
        Me.b1 = New System.Windows.Forms.Button()
        Me.b2 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'a5
        '
        Me.a5.Location = New System.Drawing.Point(152, 88)
        Me.a5.Name = "a5"
        Me.a5.TabIndex = 0
        Me.a5.Text = ""
        '
        'a4
        '
        Me.a4.Location = New System.Drawing.Point(152, 56)
        Me.a4.Name = "a4"
        Me.a4.TabIndex = 1
        Me.a4.Text = ""
        '
        'a1
        '
        Me.a1.Location = New System.Drawing.Point(16, 56)
        Me.a1.Name = "a1"
        Me.a1.TabIndex = 2
        Me.a1.Text = ""
        '
        'a2
        '
        Me.a2.Location = New System.Drawing.Point(16, 88)
        Me.a2.Name = "a2"
        Me.a2.TabIndex = 3
        Me.a2.Text = ""
        '
        'a3
        '
        Me.a3.Location = New System.Drawing.Point(16, 120)
        Me.a3.Name = "a3"
        Me.a3.TabIndex = 4
        Me.a3.Text = ""
        '
        'b1
        '
        Me.b1.Location = New System.Drawing.Point(40, 176)
        Me.b1.Name = "b1"
        Me.b1.TabIndex = 5
        Me.b1.Text = "解方程"
        '
        'b2
        '
        Me.b2.Location = New System.Drawing.Point(184, 176)
        Me.b2.Name = "b2"
        Me.b2.TabIndex = 6
        Me.b2.Text = "退出"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.b2, Me.b1, Me.a3, Me.a2, Me.a1, Me.a4, Me.a5})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      

    End Sub

    Private Sub b1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b1.Click
        Dim a!, b!, c!
        a = a1.Text
        b = a2.Text
        c = a3.Text
        If b * b - 4 * a * c >= 0 Then
            a4.Text = (-b + Sqrt(b * b - 4 * a * c)) / 2 * a
            a5.Text = (-b - Sqrt(b * b - 4 * a * c)) / 2 * a
        Else
            a4.Text = "error"
            a5.Text = "also error"
        End If
    End Sub

    Private Sub b2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles b2.Click
        End
    End Sub
End Class

⌨️ 快捷键说明

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