下面的例子采用非API的方法來判斷一個年份是否為閏年。
閏年判斷方法:能夠被4或100或400整除的年份為閏年。
在一個窗體中放入一個CommandButton,然后放入下述代碼
Option Explicit
Private Sub Command1_Click()
Print 2000,
Print IsLeapYearA(2000),
Print IsLeapYearB(2000)
Print 1999,
Print IsLeapYearA(1999),
Print IsLeapYearB(1999)
Print 1998,
Print IsLeapYearA(1998),
Print IsLeapYearB(1998)
Print 1997,
Print IsLeapYearA(1997),
Print IsLeapYearB(1997)
Print 1996,
Print IsLeapYearA(1996),
Print IsLeapYearB(1996)
End Sub
Function IsLeapYearA(ByVal yr As Integer) As Boolean
If ((yr Mod 4) = 0) Then
IsLeapYearA = ((yr Mod 100) > 0) Or ((yr Mod 400) = 0)
End If
End Function
Public Function IsLeapYearB(ByVal yr As Integer) As Boolean
IsLeapYearB = Day(DateSerial(yr, 2, 29)) = 29
End Function
閏年判斷方法:能夠被4或100或400整除的年份為閏年。
在一個窗體中放入一個CommandButton,然后放入下述代碼
Option Explicit
Private Sub Command1_Click()
Print 2000,
Print IsLeapYearA(2000),
Print IsLeapYearB(2000)
Print 1999,
Print IsLeapYearA(1999),
Print IsLeapYearB(1999)
Print 1998,
Print IsLeapYearA(1998),
Print IsLeapYearB(1998)
Print 1997,
Print IsLeapYearA(1997),
Print IsLeapYearB(1997)
Print 1996,
Print IsLeapYearA(1996),
Print IsLeapYearB(1996)
End Sub
Function IsLeapYearA(ByVal yr As Integer) As Boolean
If ((yr Mod 4) = 0) Then
IsLeapYearA = ((yr Mod 100) > 0) Or ((yr Mod 400) = 0)
End If
End Function
Public Function IsLeapYearB(ByVal yr As Integer) As Boolean
IsLeapYearB = Day(DateSerial(yr, 2, 29)) = 29
End Function