判断一个年份是否为闰年 |
|
www.nanhushi.com 佚名 不详 |
下面的例子采用非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
|
|
|
文章录入:杜斌 责任编辑:杜斌 |
|
上一篇文章: 计算机等级考试二级VB常用函数解析 下一篇文章: 浙江省高校计算机等级考试大纲(二级——VisualBasic语言程序设计大纲)( |
【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
|