Quadratic Equation Solver

Quadratic Equation Solver is a small application to find out the root(s) of the quadratic equation rapidly.
  • 6118
 

Quadratic Equation Solver is a small application which allows you to solve a quadratic equation and produce the result very fast and correct.

Here is the source code of the application "Quadratic Equation Solver"

Code :

  • Module1

Module Module1

     Public a, b, c, det, r1, r2 As Single

End Module

  • Form1 

Imports System.Console

Imports System.Math

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgsHandlesMyBase.Load

        Texta.Text = ""

        Textb.Text = ""

        Textc.Text = ""

        Textr1.Text = ""

        Textr2.Text = ""

    End Sub

    Private Sub Button4_Click(ByVal sender As System.ObjectByVal e As System.EventArgs)Handles QESExit.Click

        End

    End Sub

    Private Sub Solve_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandlesSolve.Click

        Textr1.Text = ""

        Textr2.Text = ""

        If Texta.Text = "0" Then

            MsgBox("Cofficient a must not be 0 !!!")

            Texta.Text = ""

            Texta.Focus()

        ElseIf Texta.Text = "" Or IsNothing(Texta.Text) Or IsNumeric(Texta.Text) = False Then

            MsgBox("Cofficient a must have an numberic value !!!")

            Texta.Text = ""

            Texta.Focus()

 

        ElseIf Textb.Text = "" Or IsNothing(Textb.Text) Or IsNumeric(Textb.Text) = False Then

            MsgBox("Cofficient b must have an numberic value !!!")

            Textb.Text = ""

            Textb.Focus()

 

        ElseIf Textc.Text = "" Or IsNothing(Textc.Text) Or IsNumeric(Textc.Text) = False Then

            MsgBox("Cofficient a must have an numberic value !!!")

            Textc.Text = ""

            Textc.Focus()

        Else

            a = Texta.Text

            b = Textb.Text

            c = Textc.Text

            det = (b * b) - (4 * a * c)

            If (det > 0) Then

                r1 = (-b + Sqrt(det)) / (2 * a)

                r2 = (-b - Sqrt(det)) / (2 * a)

                Answer.Text = "There are two roots :: "

                Textr1.Enabled = True

                Textr2.Enabled = True

                Textr1.Text = r1

                Textr2.Text = r2

            ElseIf (det = 0) Then

                r1 = (-b + Sqrt(det)) / (2 * a)

                Answer.Text = "There is only one root :: "

                Textr1.Enabled = True

                Textr1.Text = r1

            Else

                Answer.Text = "There is no root !!!"

            End If

        End If

    End Sub

    Private Sub Reset_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandlesReset.Click

        Texta.Text = ""

        Textb.Text = ""

        Textc.Text = ""

        Textr1.Text = ""

        Textr2.Text = ""

        Answer.Text = ""

        Textr1.Enabled = False

        Textr2.Enabled = False

        Texta.Focus()

    End Sub

    Private Sub Texta_GotFocus(ByVal sender As ObjectByVal e As System.EventArgsHandlesTexta.GotFocus

        Texta.SelectAll()

    End Sub

    Private Sub Textb_GotFocus(ByVal sender As ObjectByVal e As System.EventArgsHandlesTextb.GotFocus

        Textb.SelectAll()

    End Sub

    Private Sub Textc_GotFocus(ByVal sender As ObjectByVal e As System.EventArgsHandlesTextc.GotFocus

        Textc.SelectAll()

    End Sub

End Class

 

Output :

This is the simple view of the application

QES_1.gif

When you leave any text box as blank you will see an message box as shown in below figure

QES_2.gif

When you assign a 0 to "coefficient a" You will receive an message box as shown in below figure

QES_3.gif

Solution in case of two roots found

QES_4.gif

Solution in case of one root found

QES_5.gif

Solution in case of no root found

QES_6.gif

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.