Results 1 to 3 of 3

Thread: Quadratic Equation

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    1

    Quadratic Equation

    Here is the thing:

    I am trying to write a quadratic equation solver in Excel 2003 using Vba, creating my own formula, but I cannot figure out how to get it to display the complex roots. This is the formula, just for the first root. It is going to be the same for the second one, just changing the signs where I have to:

    Function quad1(a, b, c)

    If IsNumeric(a) And IsNumeric(b) And IsNumeric(c) Then

    If ((b ^ 2) - (4 * a * c)) >= 0 Then
    quad1 = Format((((-b) + (Sqr((b ^ 2) - (4 * a * c)))) / (2 * a)), "0.00")

    Else:
    quad1 = ((-b) / (2 * a)) & (i * ((Sqr(-((b ^ 2) - (4 * a * c)))) / (2 * a)))

    End If
    Else
    quad1 = "Input a numeric value"
    End If
    End Function


    The part that I have to fix is:
    quad1 = ((-b) / (2 * a)) & (i * ((Sqr(-((b ^ 2) - (4 * a * c)))) / (2 * a)))
    Any suggestions are welcome. Thanks !

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Quadratic Equation

    Don't look at this link if you want to do this all by yourself. Many times when I need to a little help with an equation (espcially Trig as I hate it so), I do a quick forum search here or on google. The link was the first VB-related hit.

    P.S. Welcome to the forums!
    Last edited by LaVolpe; Mar 16th, 2010 at 10:04 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Quadratic Equation

    Thread moved from 'VB6' forum to 'Office Development/VBA' forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width