View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Using COS in VBA, incorrect value returned

And just to clarify:

¶ = [Pi()]
is equivalent to:
¶ = application.evaluate("Pi()")

which could be replaced by:
¶ = application.pi

Sometimes using [] can be confusing.

Dana DeLouis wrote:

Just for fun... This is not ideal, but a fun attempt at using a Pi symbol in
vba.
You have to hold Alt key, then 0182. Plus, you have to use a little
imagination on the Pi symbol.

Sub Fun()
Dim ¶ As Double ' Alt+0182
¶ = [Pi()]
MsgBox Cos(¶)
End Sub

--
Dana DeLouis

"Gnrnr" wrote in message
ups.com...
On Sep 19, 12:22 pm, Dave Peterson wrote:
Add
Option Explicit
at the top of your module and you'll see the problem.

Dim Pi As Double
Pi = 3.141592654
MsgBox Cos(Pi)

Dave Peterson


Thanks Dave.

I'll give that a go. I thought that pi was a defined constant within
VBA though. I'm guessing it is something to do with the computer
having to think for me to create a constant on the fly so to speak?

Regards
Steve


--

Dave Peterson