Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
I did a bit of a search on this but when using VBA and having the
following equation the Cos function returns a value of 1 rather than the correct -1. What am i doing wrong? temp=cos(pi) regards Steve |
#2
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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) Gnrnr wrote: I did a bit of a search on this but when using VBA and having the following equation the Cos function returns a value of 1 rather than the correct -1. What am i doing wrong? temp=cos(pi) regards Steve -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
ps. You could use:
msgbox cos(application.pi) == or Pi = 3.14159265358979 If you need that many decimal places. 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) Gnrnr wrote: I did a bit of a search on this but when using VBA and having the following equation the Cos function returns a value of 1 rather than the correct -1. What am i doing wrong? temp=cos(pi) regards Steve -- Dave Peterson -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
#N/A value is returned | Excel Worksheet Functions | |||
No value returned in if statement | Excel Worksheet Functions | |||
need to know how to get the sum of right product returned | Excel Worksheet Functions | |||
Using the returned value of a function | New Users to Excel | |||
#Value! Returned ? | Excel Worksheet Functions |