×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Pi in VB6

 Forum Search FAQs Links MVPs

## Pi in VB6

(OP)
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)

### RE: Pi in VB6

Cant you just set up your own constant = 3.14159265358979
i.e.

Public Const Pi As Double = 3.14159265358979

### RE: Pi in VB6

(OP)
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)

### RE: Pi in VB6

(OP)
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)

### RE: Pi in VB6

How can PI be a constant?

### RE: Pi in VB6

(OP)
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)

### RE: Pi in VB6

(OP)
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)

### RE: Pi in VB6

I was just being difficult.
This is how Pi is determined:

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

### RE: Pi in VB6

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 FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'

### RE: Pi in VB6

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

### RE: Pi in VB6

"You guys pair up in groups of PI..."?

harebrain

### RE: Pi in VB6

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#)))

### RE: Pi in VB6

Debug.Print CBool(ConPI = (4# * Atn(1#)))

### RE: Pi in VB6

(OP)
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.

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

### RE: Pi in VB6

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#

### RE: Pi in VB6

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...

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

#### Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!