Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pi in VB6 1

Status
Not open for further replies.

Sashanan

Programmer
Jan 19, 2001
235
NL
I must be overlooking something obvious here, but I can't seem to use the Pi constant in VB6. What few MSDN references I can find to it aren't for VB, and several guess attempts (Pi, Pi(), Math.Pi, VbPi) all failed. So how do I use Pi in a VB calculation?


"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
Cant you just set up your own constant = 3.14159265358979
i.e.

Public Const Pi As Double = 3.14159265358979

 
That'd work, but is Pi really just not present as a VB constant? I find that hard to believe.


"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
Certainly looks like it. Well, it's a surprise, but no worries as the Double declaration will do just fine. Thanks for the insight.


"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
Simple question, very good question. Guess I didn't think this through. :)


"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
Although...even though an accurate Pi could not be caught in a constant (mainly because an accurate Pi does not exist), I would have expected there to be a rounded one. Regular Basic (at the very least my Commodore 64's Basic interpreter as well as GWBasic and QBasic on the PC) did have it defined with 8 digit precision or something.


"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
I was just being difficult[wink].
This is how Pi is determined:

Function PI() As Double
PI = 4# * Atn(1#)
End Function

 
CCLINT,
<How can PI be a constant?> Are you suggesting there are alternative values available?

(I believe that one of the southern states passed a statute defing Pi as 3 to make maths easier but......) [lol]

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Us southerners kinda use &quot;shade over three&quot; as PI...[wink]


Mark

&quot;You guys pair up in groups of three, then line up in a circle.&quot;
- Bill Peterson, a Florida State football coach
 
Then shouldn't your tag read:

&quot;You guys pair up in groups of PI...&quot;?

:)

harebrain
 
PI = 3 [lol]<bursting>

>How can PI be a constant?
Maybe I should have said:
How can good PI be a constant?[lickface]

Oh, Oh. I think I've mentioned before how bad my english spelling is...and, no, I'm not from that state.


Anyways, just for fun, check this out:

Const ConPI As Double = 3.14159265358979
Debug.Print CBool(CPI = (4# * Atn(1#)))
 
Opps. Should read:

Debug.Print CBool(ConPI = (4# * Atn(1#)))
 
Interesting...that anything like the old trick of taking out a calculator, typing in 3,141592674, then minus, then the pi button, then equals? I'd get answers like 0.1 E-14 or such.


&quot;Much that I bound, I could not free. Much that I freed returned to me.&quot;
(Lee Wilson Dodd)
 

Yep. Or similar.
Simply put: It depends how many decimal places PI is stored as OR, if it is dynamically calculated, how many decimal places the number type is able to calculate to, which is NOT the same as how many decimal places are actually displayed.

Try this (using the function I supplied)

?PI - 3.14159265358979#

 
I think this thread is now complete and over covering all aspects but I just wanted to add something related to pi which might be interesting for some readers.

Irrational numbers like pi and e (base of natural logarithm) theoretically cannot be expressed exactly. What we can do is only express them approximately. That's why 3, 22/7, 3.1415927 and 3.14159265358979, all are only approximations to pi but none of them exactly equals pi.

During high schools I deviced a method of representing these irrational numbers in the form of a simple fraction (i.e. in the form of Numerator/Denominator) with variably increasing accuracies.

Here are a few of such fractions approximating the value of pi in order of increasing complexity and accuracy.
[tt]
reference value of pi accurate upto 15
significant figures = 3.14159265358979
--------------------------------------
simple fraction decimal value
--------------------------------------
3/1 3.00000000000000
22/7 3.14285714285714
355/113 3.14159292035398
104348/33215 3.14159265392142
312689/99532 3.14159265361894
1146408/364913 3.14159265359140
...
and so on...
[/tt]
The digits represented in blue indicate those which match/coincide with the reference value of pi and those in red indicate those which do not.

All of these fractions are calculated progressively with a complex method which, I'm afraid, will be difficult for me to explain here.
Note that accuracy of these fractions improves after each iteration.

Further fractions with higher accuracies can also be calculated and those would be obviously more complex.

This method can be used to approximate other irrational numbers as well --- for instance; e, the sqare root of 2 and log(50).

Any comments on this stuff are welcome...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top