Inverse Cosine function problem

BarryClark

New member
Local time
Today, 17:39
Joined
Aug 24, 2011
Messages
5
I have a query in an access 2007 database that returns a numerical value for the cosine of an angle. I need to transform that value into the angle itself but there is no ArcCos function in Access.
I have created a new Module, which I named ArcCOS to do that but when I test it in the Immediate environment, it returns a Compile Error --- Expected Variable or Procedure, not Module.

The code for the Module I created is:

Option Compare Database

Public Function ArcCOS(ByVal nValue As Double, Optional fRadians As Boolean = True) As Double
Const PI As Double = 3.14159265359
ArcCOS = -Atn(nValue / Sqr(1 - nValue * nValue)) + PI / 2
If fRadians = False Then ArcCOS = ArcCOS * (PI / 180)
End Function

Can anyone tell me what I have got wrong?
 
Hello and welcome to the forum.
Is your nValue < 1? An nValue greater than 1 will cause you to pass a negative value to the Sqr() function, which then fails.
Probably you need to check for, and do the conversion to, radians before calculating your ACOS.
Mark
 
Everything is computed in radians and the returned value from the query calculation is less than 1. To test the module in the immediate environment, the entry I made set a value for the cosine as 0.75 as follows: ?ArcCOS(0.75)
 
Barry, I can't reproduce your error. For me the function works if I type this ...
Code:
? ArcCOS(0.75)
... in the immediate pane. It fails, as I mentioned above, if I do this ...
Code:
? arccos(30, False)
Does the compiler highlight a particular line in your code?
 
Barry,

Your module and function can't have the same name.

hth,
Wayne
 
The function seems to compile properly if I go through the Debug/Compile process, but when I test it in the immediate environment it fails. There is no indication of a failure in any specific line of code. There is just a Microsoft Visual Basic box comes up with:

Compile Error:

Expected Variable or Procedure, not Module

and OK and Help buttons

The help button provides the following response:

Expected variable or procedure, not module

There is no variable or procedure by this name in the current scope , but there is a module by this name. This error has the following cause and solution:


  • The name of a module is used as a variable or procedure. Check the spelling of the variable or procedure name, and make sure the name you want to refer to isn't private to another module. A module name can be a qualifier, but can't stand alone.
For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).
ofm

F1 just takes me to a a Help display of the Project Explorer hierarchy.
 
I think Wayne got it there Barry. Rename the module or the function and retry.
 
Thanks to both of you -- I changed the function to ACOS and that solved the problem.

I knew I was doing something stupid...............

This was the first time I had directly coded any kind function, so it was a real learning experience and I really appreciate your help.
 
Well, nicely done for a first time. To me it's the breakthroughs in learning that are the most fun.
Cheers,
 

Users who are viewing this thread

Back
Top Bottom