Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for stardate.vbs

(view source code of stardate.vbs as plain text)

  1. ' Check for command line arguments (none required)
  2. If WScript.Arguments.Count Then Syntax
  3.  
  4. ' Current year
  5. strYear = DatePart( "yyyy", Date )
  6.  
  7. ' Calculate fraction of current year
  8. ydays = DatePart("y",Date)
  9.  
  10. ' Check for leap year
  11. leapyear = 0
  12. If strYear Mod   4 = 0 Then leapyear = 1
  13. If strYear Mod 100 = 0 Then leapyear = 0
  14. If strYear Mod 400 = 0 Then leapyear = 1
  15.  
  16. ' Calculate fraction of current day
  17. dmins = 60 * DatePart( "h", Time ) + DatePart( "n", Time )
  18.  
  19. ' Calculate actual starsate
  20. stardate = "" & ( strYear - 2323 ) _
  21.          & Int( 1000 * ydays / ( 365 + leapyear ) ) _
  22.          & "." & Int( dmins / 144 )
  23.  
  24. ' Display the result
  25. WScript.Echo vbCrLf & "Stardate today is " & stardate
  26.  
  27.  
  28. Sub Syntax( )
  29. 	strMsg = vbCrLf _
  30. 	       & "StarDate.vbs,  Version 1.00" & vbCrLf _
  31. 	       & "Convert current date and time to stardate" _
  32. 	       & vbCrLf  & vbCrLf _
  33. 	       & "Usage:  CSCRIPT.EXE  STARDATE.VBS" _
  34. 	       & vbCrLf  & vbCrLf _
  35. 	       & "Based on an algorithm found on The StarTrek Gallery" _
  36. 	       & vbCrLf _
  37. 	       & "http://www.trainerscity.com/startrek/" _
  38. 	       & vbCrLf  & vbCrLf _
  39. 	       & "Written by Rob van der Woude" & vbCrLf _
  40. 	       & "http://www.robvanderwoude.com" & vbCrLf
  41. 	WScript.Echo strMsg
  42. End Sub
  43.  

page last modified: 2024-04-16; loaded in 0.0050 seconds