Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default bizarre "invalid procedure call" error

Sub Test1 below generates an "invalid procedure call or argument" erro
(#5) in Excel 97 and Excel 2003 on all of my PCs. Sub Test2 does not
Can anyone replicate this? If so, can anyone explain the problem, o
provide a workaround other than writing the variables to cells an
performing the calculations there? Thanks in advance.

Sub Test1()
Dim a As Double, b As Double, c As Double
a = -0.1
b = 0.05
c = a ^ b
End Sub

Sub Test2()
Dim c as Double
c = -0.1 ^ 0.05
End Su

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default bizarre "invalid procedure call" error

Just to clarify, the problem arises whether or not the answer is a
imaginary number. So, for example, -1 = -1 ^ (1/3) involves n
imaginary numbers, but will generate a runtime error when I assign -
and 1/3 to separate variables.

Sub test()
Dim a As Double, b As Double, c As Double
c = -1 ^ (1 / 3) 'Performs fine.
a = -1
b = 1 / 3
c = a ^ b 'Crashes.
End Su

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default bizarre "invalid procedure call" error

Pat

Replicate...yes...reason no.... It appears to be the - sign in the
variable. remove the sign and all is well. Negate it later and all is well
too

Sub Test1()
Dim a As Double, b As Double, c As Double
a = 0.1
b = 0.05
c = -(a ^ b)
Debug.Print c
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"PatFinegan " wrote in message
...
Sub Test1 below generates an "invalid procedure call or argument" error
(#5) in Excel 97 and Excel 2003 on all of my PCs. Sub Test2 does not.
Can anyone replicate this? If so, can anyone explain the problem, or
provide a workaround other than writing the variables to cells and
performing the calculations there? Thanks in advance.

Sub Test1()
Dim a As Double, b As Double, c As Double
a = -0.1
b = 0.05
c = a ^ b
End Sub

Sub Test2()
Dim c as Double
c = -0.1 ^ 0.05
End Sub


---
Message posted from
http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default bizarre "invalid procedure call" error

Not sure how do a FRACTIONAL exponent for any negative number without
getting an imaginary result. What the code you posted is doing is the
following:

c = -1 ^ (1 / 3) 'Performs fine.

First take 1/3 to get 0.333333...
Then raise 1 to the 0.333333 to get 1
Then negate it.

You can duplicate the error if you change your formula to read:

c = (-1) ^ (1 / 3) 'Error

K


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default bizarre "invalid procedure call" error

Thanks, kkknie, but a fractional root whose reciprocal is an odd intege
(as opposed to an even integer) should not generate an error on
negative number.

For example: -8 = -2 ^ 3
Therefo -2 = -8 ^ (1/3)

I added an error handler to my second post, showing how Excel handle
the equation correctly on a worksheet, but not in VBA

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default bizarre "invalid procedure call" error

Thanks, Nick, for the simple workaround. Strange discrepency betwee
Excel and VBA, though

--
Message posted from http://www.ExcelForum.com

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default bizarre "invalid procedure call" error

if you put -1 (A1) in one cell and .05 (a2) in another

=A1^A2

raises an error as well.

=-1^0.5 raises an error as well

---------------------------------------

In a worksheet, the order of operations is different:

: (colon)
(single space)

, (comma)
Reference operators
- Negation (as in -1)
% Percent
^ Exponentiation
* and / Multiplication and division
+ and - Addition and subtraction
& Connects two strings of text (concatenation)
= < <= = < Comparison


--
Regards,
Tom Ogilvy


"PatFinegan " wrote in message
...
Thanks, Nick, for the simple workaround. Strange discrepency between
Excel and VBA, though.


---
Message posted from http://www.ExcelForum.com/



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default bizarre "invalid procedure call" error

Dear Tom,

Thanks for pointing out the difference between orders of operation i
VBA and Excel.

However, to clarify, my first post c= -1^.5 should indeed hav
generated an error because the square root of a negative number i
imaginary. I immediately regretted posting it because it cluttered tw
very distinct issues -- the handling of imaginary numbers and
computational inconsistency between Excel and VBA.

That's why I added a second equation, c = -1 ^ (1/3), because the cub
root of a negative number is not imaginary and should therefore no
result in an error. But as I wrote, the equation worked fine in a
Excel spreadsheet but bombed in VBA. It is that latter computationa
discrepency that I find troubling, since the equation is definitel
"solvable". Sorry if that wasn't clear

--
Message posted from http://www.ExcelForum.com

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default bizarre "invalid procedure call" error

it appears to be a precedence/order of operations problem. If you put
parens around -0.1 you get the same problem:

Sub Test2()
Dim c As Double
c = (-0.1) ^ 0.05
End Sub


Exponention appears to have a higher precedence than negation.

--
Regards,
Tom Ogilvy


"PatFinegan " wrote in message
...
Sub Test1 below generates an "invalid procedure call or argument" error
(#5) in Excel 97 and Excel 2003 on all of my PCs. Sub Test2 does not.
Can anyone replicate this? If so, can anyone explain the problem, or
provide a workaround other than writing the variables to cells and
performing the calculations there? Thanks in advance.

Sub Test1()
Dim a As Double, b As Double, c As Double
a = -0.1
b = 0.05
c = a ^ b
End Sub

Sub Test2()
Dim c as Double
c = -0.1 ^ 0.05
End Sub


---
Message posted from http://www.ExcelForum.com/





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default bizarre "invalid procedure call" error

From help for precedence

Arithmetic
Exponentiation (^)
Negation (-)
Multiplication and division (*, /)
Integer division (\)
Modulus arithmetic (Mod)
Addition and subtraction (+, -)
String concatenation (&)



--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
it appears to be a precedence/order of operations problem. If you put
parens around -0.1 you get the same problem:

Sub Test2()
Dim c As Double
c = (-0.1) ^ 0.05
End Sub


Exponention appears to have a higher precedence than negation.

--
Regards,
Tom Ogilvy


"PatFinegan " wrote in message
...
Sub Test1 below generates an "invalid procedure call or argument" error
(#5) in Excel 97 and Excel 2003 on all of my PCs. Sub Test2 does not.
Can anyone replicate this? If so, can anyone explain the problem, or
provide a workaround other than writing the variables to cells and
performing the calculations there? Thanks in advance.

Sub Test1()
Dim a As Double, b As Double, c As Double
a = -0.1
b = 0.05
c = a ^ b
End Sub

Sub Test2()
Dim c as Double
c = -0.1 ^ 0.05
End Sub


---
Message posted from http://www.ExcelForum.com/





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error "invalid data source reference" for pivot table Manny Excel Worksheet Functions 6 April 5th 23 02:58 PM
Run-time Error '5' - Invalid procedure call or argument Trefor Excel Discussion (Misc queries) 2 December 17th 07 03:32 AM
error: "invalid character in text conent" How do I open this file RTH Excel Discussion (Misc queries) 5 April 23rd 06 03:04 PM
Run-time error '5': Invalid Procedure Call or Argument Nikila Excel Discussion (Misc queries) 2 February 24th 06 09:26 PM
Run-time error '5':Invalid Procedure call or argument Jan Refsdal Excel Programming 1 July 25th 03 05:14 AM


All times are GMT +1. The time now is 04:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"