VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get PI

by Ramon_Morales (1 Submission)
Category: Math/Dates
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

Another PI program. This one allows you to get PI for any number of decimal places up to 1000. It doesn't calculate PI, it is hard coded in! All you do is pass the number of decimal places required.

Inputs
Pass a number between 1 and 1000 and the function will return PI to that many decimal places.
Assumes
This is a function. Put in a code module. Any questions contact at me at codecommandos.com or visit my web site www.codecommandos.com .
Code Returns
Pi with the number of decimal places that the user requested.
Side Effects
None (just my tired fingers ;-)

Rate Get PI

Function GetPi(iLengthOfPI As Integer) As String
'*************************************************************
'Creation Date: 06/10/2000
'Author: Ramon Morales
'Comments: This function finds Pi to the requested number of
'decimal places. It does not calculate Pi, there is a hard
'coded string and ther result is parsed based on the requested
'number of decimal places.
'*************************************************************
Dim sPi As String
  '********************************
  'Error Trapping
  If iLengthOfPI > 1000 Or iLengthOfPI < 1 Then
    GoTo StandardExit
  End If
  '********************************
  
  sPi = "3.141592653589793238462643383279502884197" '
  sPi = sPi & "1693993751058209749445923078164"
  sPi = sPi & "0628620899862803482534211706798"
  sPi = sPi & "2148086513282306647093844609550"
  sPi = sPi & "5822317253594081284811174502841"
  sPi = sPi & "02701938521105559644622948954930"
  sPi = sPi & "38196442881097566593344612847564"
  sPi = sPi & "823378678316527120190914564856692"
  sPi = sPi & "346034861045432664821339360726024"
  sPi = sPi & "914127372458700660631558817488152"
  sPi = sPi & "092096282925409171536436789259036"
  sPi = sPi & "001133053054882046652138414695194"
  sPi = sPi & "151160943305727036575959195309218"
  sPi = sPi & "611738193261179310511854807446237"
  sPi = sPi & "996274956735188575272489122793818"
  sPi = sPi & "301194912983367336244065664308602"
  sPi = sPi & "139494639522473719070217986094370"
  sPi = sPi & "277053921717629317675238467481846"
  sPi = sPi & "766940513200056812714526356082778"
  sPi = sPi & "577134275778960917363717872146844"
  sPi = sPi & "0901224953430146549585371050792279"
  sPi = sPi & "6892589235420199561121290219608640"
  sPi = sPi & "3441815981362977477130996051870721"
  sPi = sPi & "1349999998372978049951059731732816"
  sPi = sPi & "0963185950244594553469083026425223"
  sPi = sPi & "0825334468503526193118817101000313"
  sPi = sPi & "7838752886587533208381420617177669"
  sPi = sPi & "1473035982534904287554687311595628"
  sPi = sPi & "6388235378759375195778185778053217"
  sPi = sPi & "1226806613001927876611195909216420"
  sPi = sPi & "1989"
StandardExit:
  On Error Resume Next
  If iLengthOfPI <= 1000 Then
    GetPi = Mid$(sPi, 1, (iLengthOfPI + 2))
  End If
  If iLengthOfPI > 1000 Then
    GetPi = "Length Too Long"
  End If
  If iLengthOfPI < 1 Then
    GetPi = "Length Must be at Least 1"
  End If
    
End Function

Download this snippet    Add to My Saved Code

Get PI Comments

No comments have been posted about Get PI. Why not be the first to post a comment about Get PI.

Post your comment

Subject:
Message:
0/1000 characters