判断一个年份是否为润年? 用VB写出

来源:百度知道 编辑:UC知道 时间:2024/06/07 23:17:13
请写出全部程序

dim aa as integer

aa=inputbox;

if aa mod 400==0 or (aa mod 4 == 0 and aa mod 100 <> 0) then
msgbox aa+"年是闰年"
else
msgbox aa+"年不是闰年"
end if

这是一个很简单的问题,只要知道公式,就可以了!

润年公式如下:

若公立年可以被 4 整除, 则很有可能为公立年, 除非..
这个公立年可以被 100 整除, 但是不可以被 400 整除, 就不是润年

测试程序及模组如下:

Public Function IsLeapYear(Yr As Integer) As Boolean
'设定预设返回值为 False
IsLeapYear = False
'若公立年可以被 4 整除, 则很有可能为公立年, 除非..
'这个公立年可以被 100 整除, 但是不可以被 400 整除, 就不是润年
If Yr Mod 4 = 0 Then
IsLeapYear = True
If Yr Mod 100 = 0 Then
If (Yr Mod 400) Then IsLeapYear = False
End If
End If
End Function

'在表单中放一个 CommandButton 及一个 TextBox

Private Sub Command1_Click()
If IsLeapYear(Text1.Text) Then
MsgBox "公立" & Text1.Text & "年 是 润年", 64, "是"
Els