I need to get the A, B, and C terms from any quadratic equation inputed into F(X
ID: 3667859 • Letter: I
Question
I need to get the A, B, and C terms from any quadratic equation inputed into F(X) to show up in the text boxes A, B, and C. NOTE: I AM NOT ASKING FOR THE VB CODE TO SOLVE FOR THE ROOTS. I NEED TO CODE THAT EXTRACTS THE PARAMETERS A, B, AND C FROM THE QUADRATIC EQUATION AND INPUTS INTO THE TEXTBOXES A, B ,C. Thank you.
4.2 Project II Roots for a Quadratic Equation a ou are asked to develop a visual Basic Net application that can determine roots of uadratic equation. The functional requirements of this project are as follows: Design a form to allow users to define a quadratic equation. The form should have a control control template e Figure created from the textbox 4-3). This textbox control will allow users to enter a quadratic expression. For example, if we want to determine the roots for x 2 x 1 0 The textbox control should allow users to enter in the quadratic expression in 1x 2 2x +1 ladrat Enter a quadratic equation F(x): 1x 2+2x+1 x1 x2 Calculate Clear Cancel Figure 4-3 An Example Form for the Project en a quadratic equation is entered in the textbox, the parameters (a, b, an expression should be extracted when users enter the Enter key. Th acted are then displayed in the for them parameters ectively. Hint: need to use the KeyPress event to respond to t YouExplanation / Answer
I have written the vb code for the same:
For the code I have assumed that text box name for a,b,c are a_txtbox,b_txtbox and c_txtbox.Also for the output x1 and x2 I have assumed names txtbox_root1 and txtbox_root2.
Working vb code:
Private Sub Calculate_Click()
a = Val(a_txtbox.Text)
b = Val(b_txtbox.Text)
c = Val(c_txtbox.Text)
'To compute the value of the determinant
det = (b ^ 2) - (4 * a * c)
If det > 0 Then
Lbl_numroot.Caption = 2
root1 = (-b + Sqr(det)) / (2 * a)
root2 = (-b - Sqr(det)) / (2 * a)
Answers.Caption = "The roots are "
Lbl_and.Visible = True
txtbox_root1.Visible = True
txtbox_root2.Visible = True
txtbox_root1.Text = Round(root1, 4)
txtbox_root2.Text = Round(root2, 4)
ElseIf det = 0 Then
root1 = (-b) / 2 * a
Lbl_numroot.Caption = 1
Answers.Caption = "The root is "
txtbox_root1.Visible = True
txtbox_root1.Text = root1
Else
Lbl_numroot.Caption = 0
Answers.Caption = "There is no root "
End If
End Sub
added code for extraction
Dim F_value,temp As String
Dim pos,pos2 As Double
If Asc(e.KeyChar) = 13 Then
F_value = f.Text
pos = InStr(f.Text, "x^2")
a.Text = Mid(f.Text, 1, pos - 1)
temp = Mid(f.Text, pos + 3)
pos2 = InStr(temp, "x")
b.Text = Mid(temp, pos2 - 2, pos2 - 1)
c.Text = Mid(temp, pos2 + 1)
End If