Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 109,719 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 2,031 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!




Get the moon's age to the second

Gets the moons age from new, in decimal days, accurate to the nearest second.

Submitted By: jacobjordan
Actions:
Rating:
Views: 97

Language: VB.NET

Last Modified: August 6, 2008

Snippet


  1.     Public Function GetMoonAge(ByVal Day As Date) As Double
  2.         Dim Year2 As Integer
  3.         Dim Month2 As Integer
  4.         Dim K1 As Integer
  5.         Dim K2 As Integer
  6.         Dim K3 As Integer
  7.         Dim Julian As Integer
  8.         Dim IP As Double
  9.         Dim Age As Double
  10.         Year2 = Day.Year - Math.Floor((12 - Day.Month) / 10)
  11.         Month2 = Day.Month + 9
  12.         If Month2 >= 12 Then Month2 = Month2 - 12
  13.         K1 = Math.Floor(365.25 * (Year2 + 4712))
  14.         K2 = Math.Floor(30.6 * Month2 + 0.5)
  15.         K3 = Math.Floor(Math.Floor((Year2 / 100) + 49) * 0.75) - 38
  16.         Julian = K1 + K2 + Day.Day + 59
  17.         If (Julian > 2299160) Then
  18.             Julian -= K3
  19.         End If
  20.         IP = (Julian - 2451550.1) / 29.530588853
  21.         IP -= Math.Floor(IP)
  22.         If IP < 0 Then IP += 1
  23.         Age = IP * 29.53
  24.         'By now, the age has already been calculated down to the day.
  25.         'The following calculations make it accurate to the second.
  26.         Age *= 86400
  27.         Age += ((((Day.Hour * 60) + Day.Minute) * 60) + Day.Second)
  28.         Return Age / 86400
  29.     End Function

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month