This VBA code defines variables and performs calculations to solve quadratic equations. It takes numeric input from text boxes, calculates the discriminant, and determines if there are real or imaginary roots. The results and status messages are output to other text boxes. It also includes code to clear the text boxes.
This VBA code defines variables and performs calculations to solve quadratic equations. It takes numeric input from text boxes, calculates the discriminant, and determines if there are real or imaginary roots. The results and status messages are output to other text boxes. It also includes code to clear the text boxes.
This VBA code defines variables and performs calculations to solve quadratic equations. It takes numeric input from text boxes, calculates the discriminant, and determines if there are real or imaginary roots. The results and status messages are output to other text boxes. It also includes code to clear the text boxes.
Dim a As Integer, b As Integer, c As Integer, D As Single
Dim mensaje As String, x1 As Single, x2 As Single, ALFA As Single, BETA As Single a = Val(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) If a = 0 Then If b = 0 Then mensaje = "NO HAY ECUACION" Else x1 = -c / b Text5.Text = x1 End If Else D=b^2-4*a*c mensaje = "SI HAY RAICES" If D < 0 Then ALFA = -b / (2 * a) BETA = ((-D) ^ (1 / 2)) / (2 * a) Text5.Text = ALFA & " + " & BETA & "*i" Text6.Text = ALFA & " - " & BETA & "*i" mensaje = "hay raices imaginarias" Else Text5.Text = (-b + D ^ (1 / 2)) / (2 * a) Text6.Text = (-b - D ^ (1 / 2)) / (2 * a) End If End If Text4.Text = mensaje End Sub Private Sub Command2_Click() End End Sub Private Sub Command3_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" Text5.Text = "" Text6.Text = "" Text1.SetFocus End Sub