INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a Computer / IT professional? Join TekTips now!
 Talk With Other Members
 Be Notified Of Responses
To Your Posts
 Keyword Search
 OneClick Access To Your
Favorite Forums
 Automated Signatures
On Your Posts
 Best Of All, It's Free!
*TekTips's functionality depends on members receiving email. By joining you are opting in to receive email.
Donate Today!
Do you enjoy these technical forums?
Posting Guidelines
Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Pi in VB6

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)


Glasgow (IS/ITManagement) 
17 Sep 03 3:56 
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)


Glasgow (IS/ITManagement) 
17 Sep 03 4:08 

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)


CCLINT (Programmer) 
17 Sep 03 4:20 
How can PI be a constant?


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)


CCLINT (Programmer) 
17 Sep 03 8:39 
I was just being difficult . This is how Pi is determined: Function PI() As Double PI = 4# * Atn(1#) End Function 

johnwm (Programmer) 
17 Sep 03 17:16 
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......) ________________________________________________________________ If you want to get the best response to a question, please check out FAQ2222244 first
'People who live in windowed environments shouldn't cast pointers.'


Us southerners kinda use "shade over three" as PI... Mark
"You guys pair up in groups of three, then line up in a circle."  Bill Peterson, a Florida State football coach 

Then shouldn't your tag read: "You guys pair up in groups of PI..."? harebrain 

CCLINT (Programmer) 
18 Sep 03 6:44 
PI = 3 <bursting> >How can PI be a constant? Maybe I should have said: How can good PI be a constant? 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#))) 

CCLINT (Programmer) 
18 Sep 03 6:46 
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 E14 or such. "Much that I bound, I could not free. Much that I freed returned to me." (Lee Wilson Dodd)


CCLINT (Programmer) 
22 Sep 03 2:58 
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#


Hypetia (Programmer) 
22 Sep 03 9:56 
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.
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...
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... 



