Invalid procedure call or argument.

P

Philosophaie

This worked in the upper part of my program with different parameters:
CL(k + 1) = (1 - Math.Cos(zL(k + 1) ^ 0.5)) / zL(k + 1)

previously worked as:
C(k + 1) = (1 - Math.Cos(z(k + 1) ^ 0.5)) / z(k + 1)

They were in a loop interrupted by an "if" and a "goto"


Run-time error "5":
Invalid procedure call or argument.
 
J

Joel

I can't give you an answer without know the the vaules of all the variables.
If you are passing a string (not numbers) to the cosine function that would
give this error. I would look at the array xL and make sure it contains
numbers and that the array has data at the index K+1.
 
P

Philosophaie

zL(k+1) never equals zero and if it does I have a if then loop around it.
Even with this protection the error occurs. zL(k+1) does however goes
negative and you can't take the square root of a negative number so:

If zL(k + 1) <> 0 Then
If zL(k + 1) > 0 Then
CL(k + 1) = (1 - Math.Cos(zL(k + 1) ^ 0.5)) / zL(k + 1)
SL(k + 1) = ((zL(k + 1) ^ 0.5) - Math.Sin(zL(k + 1) ^ 0.5)) /
zL(k + 1) ^ (3 / 2)
Else
CL(k + 1) = (1 - Application.WorksheetFunction.Cosh(-zL(k + 1) ^
0.5)) / zL(k + 1)
SL(k + 1) = (Application.WorksheetFunction.Sinh(-zL(k + 1) ^
0.5) - (-zL(k + 1) ^ 0.5)) / (-zL(k + 1)) ^ (3 / 2)
End If
Else
MsgBox ("z(k+1) can't divide by zero.")
End If

And the error switches to the new cosh added.
 
J

Joel

Cos and Cosh will except any real number positive or negative as well as
zero. Adn VBa doesn't have an imaginary nor complex variable type.
Threfore, the problem must be that the value is nothing. In VBA if you don't
write to a location in an array or variable the initial value is NOTHING
which will genrate the error you are getting.

try adding the following to your code

Dim Zl(100) as single 'or the size you need make surew you include a type
like
'single, double
Erase Zl 'sets array to zero
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top