Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Second Degree Solver by: [Demantor] - [Fully Compilable!] - [Demantor@live.com]
- 'Thanks for Lam, for getting the Mathimatical Background ready!
- Dim a, b, c, x, y, js As Double, lbtxt As String
- Try
- a = TextBox1.Text 'Checking valid values
- b = TextBox2.Text
- c = TextBox3.Text
- If Not a = 0 Then
- Dim root1 As String = "Root1 is: ", root2 As String = root1.Replace(1, 2)
- js = (b ^ 2) - (4 * a * c)
- If Not js < 0 Then 'js >= 0
- root1 &= (-b + Math.Sqrt(js)) / (2 * a)
- root2 &= (-b - Math.Sqrt(js)) / (2 * a)
- If js = 0 Then root2 = Nothing 'Only 1 root
- lbtxt = "Roots are real!"
- Else 'js < 0
- y = Math.Sqrt(-js) / (2 * a) 'Complex Part, In case of Real roots would return n.def.
- If Not y = -1 And Not y = 1 Then
- If Not b = 0 Then
- x = -b / (2 * a) ' Real Part
- root1 &= x & "+(" & y & ")* i"
- root2 &= x & "-(" & y & ")* i"
- lbtxt = "Not real roots!"
- Else
- root1 &= y & "* i"
- root2 &= -y & "* i"
- lbtxt = "Roots are only the imagination part!"
- End If
- Else 'js < 0 And (y = 1 Or y = -1)
- root1 &= "+i"
- root2 &= "-i"
- lbtxt = "Roots are only the 'i' part!"
- End If
- End If
- Label3.Text = lbtxt
- MsgBox(root1 & vbCrLf & root2 & vbCrLf & vbCrLf & _
- lbtxt, MsgBoxStyle.Information, "Solution!")
- Else
- MsgBox("Incorrect data input: " & a & vbCrLf & _
- "Please, correct your data!", _
- MsgBoxStyle.Critical, _
- "No numbers found or value is 0!")
- End If
- Catch ex As Exception
- MsgBox("Incorrect Values entered, please check your numbers " & _
- "and fill all the fields (fill with 0 for no value)!" & _
- vbCrLf & "Error Description: " & ex.Message, _
- MsgBoxStyle.Exclamation, "Error!")
- End Try
- Label3.Text = "Information!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement