Re: Pi in VBA?

R

Rick Rothstein

You could just assign the value to a constant directly...

Const PI = 3.14159265358979

Or you can let VB calculate it for you...

PI = 4 * ATN(1)
 
J

JoeU2004

Rick Rothstein said:
You could just assign the value to a constant directly...
Const PI = 3.14159265358979

Or you can let VB calculate it for you...
PI = 4 * ATN(1)

Your constant for PI does not equal VB 4*Atn(1) or Excel PI().

However, if you enter the constant as 3.141592653589793, that does result in
the same binary value as 4*Atn(1) and PI(), even though VB will not display
the last 3.
 
D

Dana DeLouis

Hi. Just to be a little different...
Not really recommended, but a poor-man's version of the Pi symbol can
sometimes be done via the Paragraph symbol. You have to have a little
imagination thou to see it as Pi :>)

Sub Demo()
Dim c
Dim ¶ 'Alt + 0182

¶ = [Pi()]

c = 2 * ¶ * 5
End Sub

Dana DeLouis
= = = =
 
A

AltaEgo

Thank you.

Wrapping in [ ] instead of Application.WorksheetFunction is new
information for me. Hopefully, the memory banks will retain this gem.

--
Steve

Dana DeLouis said:
Hi. Just to be a little different...
Not really recommended, but a poor-man's version of the Pi symbol can
sometimes be done via the Paragraph symbol. You have to have a little
imagination thou to see it as Pi :>)

Sub Demo()
Dim c
Dim ¶ 'Alt + 0182

¶ = [Pi()]

c = 2 * ¶ * 5
End Sub

Dana DeLouis
= = = =

Prof said:
This is why I don't want to hard code a trancendental constant.
 
N

Nick H

------snip------
Sub Demo()
Dim c
Dim ¶ 'Alt + 0182

¶ = [Pi()]

c = 2 * ¶ * 5
End Sub
------snip------

That is SO neat!

The poor sods who inherit my code are going to be scratching their
heads at all the weird variable symbols that are going to be cropping
up. <vbg>

Nick H
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top