Results 1 to 8 of 8

Thread: [RESOLVED] Really Annoying Invalid Procedure Call or Argument

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    448

    Resolved [RESOLVED] Really Annoying Invalid Procedure Call or Argument

    This is so pissing me off!

    Can anyone figure out what the heck is going on here?

    As you can see in the attached screen capture, the error is being raised on the highlighted line in the code. But what is causing the error?! If you look at the Immediate Window, you can see that I can take the contents of the variable, "Righto_PREP1" and raise it to the "LoftExp" power with no problem. But when I try to simply let it do the operation as shown in the Code Window, it fails. All of my variables are double precision as you can see, and there are no reserved words being used as variable names.

    I'm stumped!

    Many thanks for any replies.
    Attached Images Attached Images  

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    448

    Re: Really Annoying Invalid Procedure Call or Argument

    ...and what is stranger still, is that my calculator has the same problem, so I am doing something fundamentaly stupid here, but my brain fart is now so big, my eyes have exploded.

  3. #3
    Addicted Member leinkyle's Avatar
    Join Date
    Mar 2008
    Location
    Manila
    Posts
    150

    Re: Really Annoying Invalid Procedure Call or Argument

    what are those variable types anyway??, as i saw on your declaration area, righttoprep1,righttoprep2 dont have any datatypes
    so i think the system will assign it as a variant, i think by a small chance. try to add a data type on your declaration. if your trying to compute declare it as a double
    vb Code:
    1. Public RighttoPREP1 as Double,RighttoPREP2 as Double
    and so as the other variable, depending on their usage
    No matter how hard life is, you still have to learn how to smile..ayt?!


    Sorry still a Newbie

    As a developer, one of your inherent traits is supposed to be your flexibility and adaptability to any new environment.
    "Aargh, not the eyes, oh it burns. It burns!"

    ---mhendak

  4. #4
    Addicted Member leinkyle's Avatar
    Join Date
    Mar 2008
    Location
    Manila
    Posts
    150

    Re: Really Annoying Invalid Procedure Call or Argument

    and oh, i forgot, the program will accept data from textbox right?? try this
    i think the problem is, the inputted data is red as a string and not a number so try to convert it to a number first.
    vb Code:
    1. RighttoPREP1=val(txtNo.text)     'to convert the inputted data into a number
    2. RighttoPREP2=RighttoPREP1 ^ LoftExp

    and oh, why are you converting the result into a string??
    vb Code:
    1. text1.text=str(RighttoPREP2)
    2. text1.text=RighttoPREP2      'use this instead

    i hope i helped you
    Last edited by leinkyle; Apr 18th, 2008 at 04:10 AM.
    No matter how hard life is, you still have to learn how to smile..ayt?!


    Sorry still a Newbie

    As a developer, one of your inherent traits is supposed to be your flexibility and adaptability to any new environment.
    "Aargh, not the eyes, oh it burns. It burns!"

    ---mhendak

  5. #5
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Really Annoying Invalid Procedure Call or Argument

    From MSDN Documetation of ^ Operator
    result = number^exponent

    A number can be negative only if exponent is an integer value. When more than one exponentiation is performed in a single expression, the ^ operator is evaluated as it is encountered from left to right.
    Looks like you'll have to remember the sign of RightoPREP1 and Abs() it in the calculation and then apply the original sign back to RightoPREP2.
    Code:
    Private Sub Command1_Click()
    Dim intx As Integer
    xBaseMax = 3
    a = 8
    xmax = 6.8
    LoftExp = 1.2
    RightoPREP1 = ((-xBaseMax * a * Abs((xe) - xmax)) / xmax)
    intx = Sgn(RightoPREP1)
    RightoPREP2 = Abs(RightoPREP1) ^ (LoftExp)
    RightoPREP2 = RightoPREP2 * intx
    End Sub
    Last edited by Doogle; Apr 18th, 2008 at 04:44 AM.

  6. #6
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Really Annoying Invalid Procedure Call or Argument

    Quote Originally Posted by Doogle
    intx = Sgn(RightoPREP1)
    RightoPREP2 = Abs(RightoPREP1) ^ (LoftExp)
    RightoPREP2 = RightoPREP2 * intx
    Although those 3 lines will prevent the error happens, but that is incorrect.
    We cannot say: (-4)0.5 = Sgn(-4)*(Abs(-4))0.5 = (-1)*40.5 = -√(4) = -2
    Because: (-4)0.5 = √(-4) is invalid on "Real" numbers.

    Only you can have:
    Code:
    ... ...
    LoftExp = 1.2
    RightoPREP1 = ((-xBaseMax * a * Abs((xe) - xmax)) / xmax)
    If LoftExp = Int(LoftExp) Or RightoPREP1 >= 0 Then
       RightoPREP2 = RightoPREP1 ^ LoftExp
    Else
       ... ...
    End If
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    448

    Re: Really Annoying Invalid Procedure Call or Argument

    leynkyle>
    1. the data types are taken care of by the DefDbl A-Z statement.
    2. No, the textbox merely reports the result from the computation.
    Thank you for the response, however.

    doogle, anhn>
    AAAHHHH!!!...THANKS FOR RESETTING MY BRAIN! Now I see that it was a heiarchy issue. The varable, RightoPREP1 CONTAINED the (-) sign so vb operated it first as if it was in parentheses with the value, THEN calculated the exponent. But in the Immediate Window, vb could separate the (-) sign out and use the standard heirarchy rules to evaluate the exponent first, THEN the (-) sign.

    Major, MAJOR brain fart. I just couldn't see the dumb error I was making. That's what happens when you work late. Thanks for the reboot.

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Really Annoying Invalid Procedure Call or Argument

    Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer. Also if someone has been particularly helpful, or even particularly unhelpful, you have the ability to affect a their forum "reputation" by rating their post. Your rating won't actually count until you have 20 posts, but the person you rate will see it and know that you appreciate their help.

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