Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Using COS in VBA, incorrect value returned

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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Using COS in VBA, incorrect value returned

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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Using COS in VBA, incorrect value returned

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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Using COS in VBA, incorrect value returned

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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 947
Default Using COS in VBA, incorrect value returned

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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
#N/A value is returned Sai Excel Worksheet Functions 7 July 15th 07 11:05 PM
No value returned in if statement Shellack Excel Worksheet Functions 3 March 23rd 06 07:49 PM
need to know how to get the sum of right product returned farmer Excel Worksheet Functions 5 March 7th 06 01:10 PM
Using the returned value of a function adombrowski New Users to Excel 1 December 21st 05 07:01 AM
#Value! Returned ? John Excel Worksheet Functions 2 December 6th 04 08:55 PM


All times are GMT +1. The time now is 07:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"