Runtime Error 5 is Driving up the Wall

  • Thread starter Thread starter Frank The Novice
  • Start date Start date
F

Frank The Novice

Hello All,

Do any of you fine folks know why I keep getting a runtime error 5 when I
run this code?

'Mean time of sunrise (msr) and Time of Sunrise (ts)
msr = 90 - Val(lo)
tr1 = (Tan(Val(la))) * (Tan(dls)) + 0.10453 + (Cos(Val(la))) / (Cos(dls))
tr2 = ArcSin(tr1)
tsr = msr - tr2 + et

The code runs to this point, then I get a "Runtime Error 5 - Invalid
Procedure Call or Argument".

The deBug shows this as the culprit, but I can't figure out why.

Function ArcSin(X As Double) As Double
If X = 1 Then
ArcSin = PI() / 2
ElseIf X = -1 Then
ArcSin = -PI() / 2
Else
-- ArcSin = Atn(X / Sqr(-X * X + 1)) --
End If
End Function

Any ideas,

Frank
 
There's no built in PI() function. Have you written your own?

As well, if X is greater than one, (-X * X + 1) will be a negative number,
which is invalid for the Sqr function.
 
Thanks for taking the time to reply, Doug.

To answer your question, yes I have written a function for PI:

Function PI() As Double
PI = Atn(1) * 4
End Function

And, no, in this case X = -1.67714042266564.

Any other thoughts?

Frank
 
Frank The Novice said:
And, no, in this case X = -1.67714042266564.


There's the problem. (when I said "X > 1", I really meant "Abs(X) > 1")

When X = -1.67714042266564, (-X * X + 1) = -1.81279999733908, and you can't
take the square root of a negative number.

Negation (unary -) takes precedence over multiplication.
 
Thanks for the help, Doug. I'll have to find another way to get ArcSin of
this number.

Frank
 
Back
Top