# Check if a particular year is a LEAP year

By definition, a year is a LEAP year if all of these conditions are true …

a) The number is a whole multiple of 4
b) If the number is a whole multiple of 100 it is also a whole multiple of 400

So, 1600 and 2000 are LEAP years … but 1700, 1800, 1900 and 2100 are NOT LEAP years.

You deploy this subroutine (IsThisALeapYear) by supplying the value to be checked in variable [IsThisALeapYear/Input] … and upon return, examine the contents of [IsThisAleapYear/Answer] for values “True” or “False”… here is an example code snippet …

``````SetVar "[IsThisALeapYear/Input]" "[TextEntry1]"
GoSub "IsThisALeapYear"
AlertBox "Yes" "[TextEntry1] is a LEAP year"
Else
AlertBox "No" "[TextEntry1] is NOT a LEAP year"
EndIf
``````

Note that the subroutine expects the year to include the century … if you supply the short form value of (say) 32, it will be treated like the year 32 (i.e. in the first century).

And here is the subroutine you would paste in your App’s SubRoutines section …

``````:IsThisALeapYear
... examines [IsThisALeapYear/Input] and returns True/False in [IsThisALeapYear/Answer]
...
... if not divisible by 4, not a leap year
Math "[IsThisALeapYear/Input]/4" "0" "[IsThisALeapYear/Y1]"
Math "[IsThisALeapYear/Input]-([IsThisALeapYear/Y1]*4)" "0" "[IsThisALeapYear/Y2]"
If "[IsThisALeapYear/Y2]" "<>" "!0"
Return
EndIf
...
... divisible by 4 ... if not divisible by 100, it is leap year
Math "[IsThisALeapYear/Input]/100" "0" "[IsThisALeapYear/Y1]"
Math "[IsThisALeapYear/Input]-([IsThisALeapYear/Y1]*100)" "0" "[IsThisALeapYear/Y2]"
If "[IsThisALeapYear/Y2]" "<>" "!0"
Return
EndIf
...
... divisible by 4 ... divisible by 100 ... if divisible by 400, it is leap year
Math "[IsThisALeapYear/Input]/400" "0" "[IsThisALeapYear/Y1]"
Math "[IsThisALeapYear/Input]-([IsThisALeapYear/Y1]*400)" "0" "[IsThisALeapYear/Y2]"
If "[IsThisALeapYear/Y2]" "=" "!0"
``````Call "gkIsThisALeapYear" "[TextEntry1]" "[Result]"