Search This Blog

Tuesday 5 April 2016

QUADRATIC EQUATION ROOT CALCULATOR WITH COMPLEX ROOT ON VISUAL BASIC Part 2 (FORM)

Ok guys, here is the second part of the quadractic equation solver but here it is created on windows form (having GUI).

Ok here is the code for the form........

Public Class Form1
    Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
        Try

            Dim a = Convert.ToDouble(textBox1.Text)
            Dim b = Convert.ToDouble(textBox2.Text)
            Dim c = Convert.ToDouble(textBox3.Text)
            Dim x1 As Double, x2 As Double, d As Double
            Dim eg As Double = Math.Pow(b, 2) - (4 * a * c)
            If eg > 0 Then
                d = Math.Sqrt(eg)
                x1 = (-b + eg) / (2 * a)
                x2 = (-b - eg) / (2 * a)
                label6.Text = "Real roots: x1 = " + x1.ToString() + ", x2 = " + x2.ToString()
            ElseIf eg = 0 Then
                x1 = -b / 2
                label6.Text = "Equal roots: x1 = " + x1.ToString() + ", x2 = " + x1.ToString()
            Else : d = Math.Round(Math.Sqrt(-1 * eg) / 2, 2)
                x1 = -b / 2
                label6.Text = "Complex roots: x1 = " + x1.ToString() + " + i" + d.ToString() + "     x2 = " + x1.ToString() + " - i" + d.ToString()
            End If

        Catch ex As Exception
            MessageBox.Show("Invalid Input", "Error")
        End Try
    End Sub
End Class

Here is the Output



Video Output

Thanks for Reading...

No comments:

Post a Comment