Powered by GeSHi

Source code for leapyear.kix

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

  1. ; LeapYear.kix,  Version 1.00
  2. ; Check if the specified or current year is a leap year
  3.  
  4. ; Default is current year
  5. If $Year = ""
  6. 	$Year = @YEAR
  7. EndIf
  8.  
  9. ; Check if the specified parameter is a number
  10. If Val( $Year ) = 0
  11. 	If "$Year" <> "0"
  12. 		GoTo Syntax
  13. 	EndIf
  14. EndIf
  15.  
  16. ; Check if the specified year is within range
  17. If $Year < 1
  18. 	GoTo Syntax
  19. EndIf
  20. If $Year > 9999
  21. 	GoTo Syntax
  22. EndIf
  23.  
  24. ; OK, continue
  25. $Year = Val( $Year )
  26.  
  27. ; Initialize
  28. $LeapYear = 0
  29. ; A leap year is any multiple of 4...
  30. $Test = $Year / 4
  31. $Test = $Test * 4
  32. If $Year = $Test
  33. 	$LeapYear = 1
  34. EndIf
  35. ; ...except if it is a multiple of 100...
  36. $Test = $Year / 100
  37. $Test = $Test * 100
  38. If $Year = $Test
  39. 	$LeapYear = 0
  40. EndIf
  41. ; ...unless it is a multiple of 400!
  42. $Test = $Year / 400
  43. $Test = $Test * 400
  44. If $Year = $Test
  45. 	$LeapYear = 1
  46. EndIf
  47.  
  48. ; Display the result
  49. $Is = "IS"
  50. If $LeapYear = 0
  51. 	$Is = "is NOT"
  52. EndIf
  53. ? "$Year $Is a leap year"
  54.  
  55. ; Exit with proper return code
  56. Quit $LeapYear
  57.  
  58.  
  59. :Syntax
  60. ? "LeapYear.kix,  Version 1.00"
  61. ? "Check if the specified year is a leap year."
  62. ?
  63. ? "Usage:   KIX32  LEAPYEAR.KIX  [ $$Year=year ]"
  64. ?
  65. ? "Where:   " + Chr(34) + "year" + Chr(34)
  66. " should be within the range of 1 through 9999."
  67. ? "         Default is the current year, if none is specified."
  68. ?
  69. ? "Returns: 0  if NOT a leap year"
  70. ? "         1  on leap years"
  71. ? "         2  on syntax errors"
  72. ?
  73. ? "Note:    Due to KiXtart's command line parsing, specifying the year 0 on the"
  74. ? "         commandline will have the same effect as not specifying a year at all."
  75. ?
  76. ? "Written by Rob van der Woude"
  77. ? "http://www.robvanderwoude.com"
  78. ?
  79. Quit 2
  80.