quadratic equation using functions
How can i put this Vb code in Vb.net Code, and make the same thing but using functions.
Thank's!
Dim A, B, C As Single
Private Sub Command1_Click()
A = Val(A1.Text) '''1
B = Val(B1.Text) '''6
C = Val(C1.Text) '''8
Dim h1, h2, x1, x2
'''h1 = B * B
h2 = B * B - 4 * A * C '''4
'''h2 = h1 + h2
h1 = Sqr(h2) '''2
'''**** h1 ****
'''****** X1 ******
x1 = -1 * B + h1
x1 = x1 / (2 * A)
x2 = -1 * B - h1
x2 = x2 / (2 * A)
x11.Caption = "X1 = " + Str(x1)
x22.Caption = "X2 = " + Str(x2)
End Sub
Procedures to make quadratic equation
thank's, but i can“t do it like that, i have to use procedures, something like this
Public Function ...(Byval ... as integer)
Code...
End Function
I have to use Functions like that to made the program, and call them from one to others, the command1_click will have very few code.
sorry about my english is because im Portuguese:).
Using Structures and a Function
Here you go...
Code:
Private Structure quadratic
Dim x1 As String
Dim x2 As String
End Structure
Private Function retQuadratic(ByVal a As Single, ByVal b As Single, ByVal c As Single) As quadratic
Dim h, tx1, tx2 As Single
h = b ^ 2 - 4 * a * c
If h > 0 Then
retQuadratic.x1 = (-b + Math.Sqrt(h)) / (2 * a)
retQuadratic.x2 = (-b - Math.Sqrt(h)) / (2 * a)
Else
tx1 = -b / (2 * a)
tx2 = Math.Sqrt(Math.Abs(h)) / (2 * a)
retQuadratic.x1 = tx1 & " + i" & tx2
retQuadratic.x2 = tx1 & " - i" & tx2
End If
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim vals As quadratic
vals = retQuadratic(1, 5, 3)
TextBox1.Text = vals.x1
TextBox2.Text = vals.x2
End Sub
Good Luck
create a class for quadratic equation
Hi again!
Your code where very helpfull for me thank's a lot.
But now i need to create a class to resolve the equation(quadratic equation), could you help me doing that!?