Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Quadratic Equation

bwhaley98133bwhaley98133 Posts: 3Member
My program calls for the quadratic equation. Three different text boxes for inputting the "A", "B", and "C" variables. Then two different text boxes for the positive and negative answers. So far here is my coding. I know that there are mistakes in the code but Hey I'm just a beginner.


Private Sub cmdCalculate_Click()
Dim intAvariable As Integer
Dim intZ As Integer
Dim intx As Integer
Dim intBvariable As Integer
Dim intCvariable As Integer
'quadratic equation = negative B plus/minus square root of 4*A*C divided by 2*A

intBvariable = -intBvariable
intZ = intAvariable * 2
intx = intAvariable * 4 * intCvariable

Me.txtMinus = intBvariable - sqrtintX / intZ
Me.txtPlus = intBvariable + sqrtintX / intZ
End Sub


Thanks for your input,

Bryan

Comments

  • PavlinIIPavlinII Posts: 404Member
    : My program calls for the quadratic equation. Three different text boxes for inputting the "A", "B", and "C" variables. Then two different text boxes for the positive and negative answers. So far here is my coding. I know that there are mistakes in the code but Hey I'm just a beginner.
    :
    :
    : Private Sub cmdCalculate_Click()
    : Dim intAvariable As Integer
    : Dim intZ As Integer
    : Dim intx As Integer
    : Dim intBvariable As Integer
    : Dim intCvariable As Integer
    : 'quadratic equation = negative B plus/minus square root of 4*A*C divided by 2*A
    :
    : intBvariable = -intBvariable
    : intZ = intAvariable * 2
    : intx = intAvariable * 4 * intCvariable
    :
    : Me.txtMinus = intBvariable - sqrtintX / intZ
    : Me.txtPlus = intBvariable + sqrtintX / intZ
    : End Sub
    :
    :
    : Thanks for your input,
    :
    : Bryan
    :
    Hi, "quadratic equation"? The generic algorithm of this equation looks different from yours...
    [code]Private Sub cmdCalculate_Click()
    Dim A As Integer, B As Integer, C As Integer, X1 As Double, X2 As Double
    Dim D As Integer 'Discriminant
    A = txtA.Text
    B = txtB.Text
    C = txtC.Text
    If A = 0 Then
    MsgBox "This is not quadratic equation"
    txtA.SetFocus
    Exit Sub
    End If
    D = B ^ 2 - 4 * A * C
    If D < 0 Then
    lblStatus.Caption = "This equation has no results"
    lblX1.Caption = vbNullString
    lblX2.Caption = vbNullString
    ElseIf D = 0 Then
    X1 = -B / (2 * A)
    lblStatus.Caption = "This equation has one result"
    lblX1.Caption = X1
    lblX2.Caption = vbNullString
    Else 'D > 0
    X1 = (-B + D ^ (1 / 2)) / (2 * A)
    X2 = (-B - D ^ (1 / 2)) / (2 * A)
    lblStatus.Caption = "This equation has two results"
    lblX1.Caption = X1
    lblX2.Caption = X2
    End If
    End Sub[/code]Create txtA, txtB, txtC textboxes and lblStatus, lblX1 and lblX2 labels..


    PavlinII
Sign In or Register to comment.