title: Quadratic Equation Visual Basic 2010+
body: <p>I have to write a program which calculate quadratic equation and find its roots. The roots <em>must</em> be displayed via MsgBox-es, and the variables A, B and C <em>must</em> be entered via InputBox-es. For now I have written this, but it somehow doesn't work and I can't figure out why. 
  **I'm new to Visual Basic .. </p>
  
  <pre><code>Public Class Form1
  Dim A As Integer
  Dim B As Integer
  Dim C As Integer
  Dim Det As Double
  Dim x1 As Double
  Dim x2 As Double
  
  
  Private Sub txtA_Click(sender As Object, e As EventArgs) Handles txtA.Click
      txtA.Text = InputBox("Please, enter value of the variable A.", "Enter A")
  End Sub
  
  Private Sub txtB_Click(sender As Object, e As EventArgs) Handles txtB.Click
      txtB.Text = InputBox("Please, enter value of the variable B.", "Enter B")
  End Sub
  
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
  End Sub
  
  Private Sub cmdCalculate_Click(sender As Object, e As EventArgs) Handles cmdCalculate.Click
      A = Val(txtA.Text)
      B = Val(txtB.Text)
      C = Val(txtC.Text)
      Det = B ^ 2 + 4 * A * C
      If Det &gt; 0 Then
          x1 = (-B + Math.Sqrt(Det)) / (2 * A)
          x2 = (-B - Math.Sqrt(Det)) / (2 * A)
          MsgBox("The roots are " + x1 + " and " + x2 + " ! ", 64, "2 Roots")
      ElseIf Det = 0 Then
          x1 = -B / (2 * A)
          MsgBox("The roots are " + x1 + " ! ", 64, "1 Double Root")
      ElseIf Det &lt; 0 Then
          MsgBox("No roots ! ", 64, "No Roots")
      End If
  
  End Sub
  
  Private Sub txtC_Click(sender As Object, e As EventArgs) Handles txtC.Click
      txtC.Text = InputBox("Please, enter value of the variable C.", "Enter C")
  End Sub
  
  Private Sub cmdExit_Click(sender As Object, e As EventArgs) Handles cmdExit.Click
      End
  End Sub
  
  Private Sub cmdClear_Click(sender As Object, e As EventArgs) Handles cmdClear.Click
      txtA.Text = ""
      txtB.Text = ""
      txtC.Text = ""
  End Sub
  </code></pre>
  
  <p>End Class</p>
  
  <p><a href="http://imgur.com/hIcDxFv" rel="nofollow">http://imgur.com/hIcDxFv</a> &lt;-- Screen view</p>