Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for leapyear.vbs

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

  1. ' LeapYear.vbs,  Version 1.00 for Windows Script Host
  2. ' Check if the specified year is a leap year.
  3. '
  4. ' Written by Rob van der Woude
  5. ' http://www.robvanderwoude.com
  6.  
  7. Select Case WScript.Arguments.Count
  8. 	Case 0
  9. 		' Default is current year
  10. 		MyYear = Year( Date )
  11. 	Case 1
  12. 		' Check datatype and range of argument
  13. 		On Error Resume Next
  14. 		MyYear = CLng( WScript.Arguments(0) )
  15. 		If Err.Number Then Syntax
  16. 		Err.Clear
  17. 		On Error Goto 0
  18. 		If MyYear < 0    Then Syntax
  19. 		If MyYear > 9999 Then Syntax
  20. 	Case Else
  21. 		Syntax
  22. End Select
  23.  
  24. LeapYear = 0
  25. If MyYear Mod   4 = 0 Then LeapYear = 1
  26. If MyYear Mod 100 = 0 Then LeapYear = 0
  27. If MyYear Mod 400 = 0 Then LeapYear = 1
  28.  
  29. strIs = " IS"
  30. If LeapYear = 0 Then strIs = " is NOT"
  31. WScript.Echo( MyYear & strIs & " a leap year" )
  32.  
  33. WScript.Quit( LeapYear )
  34.  
  35.  
  36. Sub Syntax
  37. msg = vbCrLf & "LeapYear.vbs,  Version 1.00 for WSH 1.0" & vbCrLf & _
  38.       "Check if the specified year is a leap year." & vbCrLf & _
  39.       vbCrLf & "Usage:   CScript  LEAPYEAR.VBS  [ year ]" & vbCrLf & vbCrLf & _
  40.       "Where:   " & Chr(34) & "year" & Chr(34) & _
  41.       " should be within the range of 0 through 9999." & vbCrLf & _
  42.       "         Default is the current year, if none is specified." & _
  43.       vbCrLf & vbCrLf & _
  44.       "Returns: 0  if NOT a leap year" & vbCrLf & _
  45.       "         1  on leap years" & vbCrLf & _
  46.       "         2  on syntax errors" & vbCrLf & vbCrLf & _
  47.       "Written by Rob van der Woude" & vbCrLf & _
  48.       "http://www.robvanderwoude.com"
  49. Wscript.Echo( msg )
  50. WScript.Quit(2)
  51. End Sub
  52.  

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