0% found this document useful (0 votes)
48 views3 pages

The Code: ' To Set All Values To Zero

This code defines the behavior of buttons in a user interface for solving quadratic equations. When the "New" button is clicked, all text boxes and labels are cleared. When the "Solve" button is clicked, it reads values from text boxes, calculates the discriminant, determines the number and values of roots, and displays the results.

Uploaded by

Mushawatu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views3 pages

The Code: ' To Set All Values To Zero

This code defines the behavior of buttons in a user interface for solving quadratic equations. When the "New" button is clicked, all text boxes and labels are cleared. When the "Solve" button is clicked, it reads values from text boxes, calculates the discriminant, determines the number and values of roots, and displays the results.

Uploaded by

Mushawatu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

The Code

Private Sub Form_Load()


End Sub

Private Sub new_Click()


' To set all values to zero
Coeff_a.Text = ""
Coeff_b.Text = ""
Coeff_c.Text = ""
Answers.Caption = ""
txt_root1.Visible = False
txt_root2.Visible = False
txt_root1.Text = ""
txt_root2.Text = ""
Lbl_and.Visible = False
Lbl_numroot.Caption = ""
End Sub
FORM 3

Private Sub Solve_Click()

Dim a, b, c, det As Integer


Dim root1, root2 As Single
Dim numroot As Integer

a = Val(Coeff_a.Text)
b = Val(Coeff_b.Text)
c = Val(Coeff_c.Text)
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
txt_root1.Visible = True
txt_root2.Visible = True
txt_root1.Text = Round(root1, 4)
txt_root2.Text = Round(root2, 4)

ElseIf det = 0 Then


root1 = (-b) / 2 * a
Lbl_numroot.Caption = 1
Answers.Caption = "The root is "
txt_root1.Visible = True
txt_root1.Text = root1
Else
Lbl_numroot.Caption = 0
Answers.Caption = "There is no root "
End If
End Sub
The Code
Private Sub Solve_Click()
Dim a, b, c, d, m, n As Integer
Dim x, y As Double

a = Val(Txt_a.Text)
b = Val(Txt_b.Text)
m = Val(Txt_m.Text)
c = Val(Txt_c.Text)
d = Val(Txt_d.Text)
n = Val(Txt_n.Text)
x = (b * n - d * m) / (b * c - a * d)
y = (a * n - c * m) / (a * d - b * c)
Lbl_x.Caption = Round(x, 2)
Lbl_y.Caption = Round(y, 2)

End Sub

You might also like