|
-
Jun 21st, 2004, 08:51 AM
#1
Thread Starter
New Member
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
-
Jun 21st, 2004, 09:20 AM
#2
Frenzied Member
Ugh, I just had a horrible Calculus flashback....
What is the whole equation again, I forget offhand, that'll help come up with an answer for you.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jun 21st, 2004, 09:46 AM
#3
Member
try this
create three textbox for input
create two textbox for output
Code:
dim a, b, c, h, tx1,tx2 as single
dim x1,x2 as string
if isnumeric(textbox1.text) and isnumeric(textbox2.text) and isnumeric(textbox2.text)
a = ctype(textbox1.text,single)
b = ctype(textbox2.text,single)
c = ctype(textbox3.text,single)
h=b^2-4*a*c
if h > 0
x1 = (-b+math.sqrt(h))/(2*a)
x2 = (-b-math.sqrt(h))/(2*a)
else
tx1 = -b/(2*a)
tx2 = math.sqrt(math.abs(h)))/(2*a)
x1 = tx1 & " + i" & tx2
x2 = tx1 & " - i" & tx2
end if
textBox4.text = x1
textbox5.text = x2
U S A
Visual Studio .NET
Windows XP
-
Jun 22nd, 2004, 06:59 AM
#4
Thread Starter
New Member
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 .
-
Jun 22nd, 2004, 02:30 PM
#5
Member
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
U S A
Visual Studio .NET
Windows XP
-
Jun 23rd, 2004, 03:08 AM
#6
Thread Starter
New Member
Thank's a lot, really... Thank you!!!
-
Jun 30th, 2004, 05:45 AM
#7
Thread Starter
New Member
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!?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|