Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.48 KB | None | 0 0
  1.         'Second Degree Solver by: [Demantor] - [Fully Compilable!] - [Demantor@live.com]
  2.         'Thanks for Lam, for getting the Mathimatical Background ready!
  3.         Dim a, b, c, x, y, js As Double, lbtxt As String
  4.         Try
  5.             a = TextBox1.Text 'Checking valid values
  6.             b = TextBox2.Text
  7.             c = TextBox3.Text
  8.             If Not a = 0 Then
  9.                 Dim root1 As String = "Root1 is: ", root2 As String = root1.Replace(1, 2)
  10.                 js = (b ^ 2) - (4 * a * c)
  11.                 If Not js < 0 Then 'js >= 0
  12.                     root1 &= (-b + Math.Sqrt(js)) / (2 * a)
  13.                     root2 &= (-b - Math.Sqrt(js)) / (2 * a)
  14.                     If js = 0 Then root2 = Nothing 'Only 1 root
  15.                     lbtxt = "Roots are real!"
  16.                 Else 'js < 0
  17.                     y = Math.Sqrt(-js) / (2 * a) 'Complex Part, In case of Real roots would return n.def.
  18.                     If Not y = -1 And Not y = 1 Then
  19.                         If Not b = 0 Then
  20.                             x = -b / (2 * a) ' Real Part
  21.                             root1 &= x & "+(" & y & ")* i"
  22.                             root2 &= x & "-(" & y & ")* i"
  23.                             lbtxt = "Not real roots!"
  24.                         Else
  25.                             root1 &= y & "* i"
  26.                             root2 &= -y & "* i"
  27.                             lbtxt = "Roots are only the imagination part!"
  28.                         End If
  29.                     Else 'js < 0 And (y = 1 Or y = -1)
  30.                         root1 &= "+i"
  31.                         root2 &= "-i"
  32.                         lbtxt = "Roots are only the 'i' part!"
  33.                     End If
  34.                 End If
  35.                 Label3.Text = lbtxt
  36.                 MsgBox(root1 & vbCrLf & root2 & vbCrLf & vbCrLf & _
  37.                           lbtxt, MsgBoxStyle.Information, "Solution!")
  38.             Else
  39.                 MsgBox("Incorrect data input: " & a & vbCrLf & _
  40.                   "Please, correct your data!", _
  41.                   MsgBoxStyle.Critical, _
  42.                   "No numbers found or value is 0!")
  43.             End If
  44.         Catch ex As Exception
  45.             MsgBox("Incorrect Values entered, please check your numbers " & _
  46.                    "and fill all the fields (fill with 0 for no value)!" & _
  47.                    vbCrLf & "Error Description: " & ex.Message, _
  48.                    MsgBoxStyle.Exclamation, "Error!")
  49.         End Try
  50.         Label3.Text = "Information!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement