1、打开Visual Basic软件(VB软件),新建工程,在Form1窗体黑点区域双击进入form1的编辑区域:
2、清空后,就可以编写代码了。这里在输入栏中输入年份,输入之后点击确定,就会在Form1中会显示出是否闰年。关于闰年的判断只要满足能被4整除不能被100整除或者被4和400整除就是达成条件,最后保存即可:
3、保存后运行查询,在form1中输入一个年份,点击确定即可输出是否为闰年:
Private Sub Command1_Click()
If Text1.Text Mod 4 = 0 And Text1.Text Mod 100 <> 0 Or Text1.Text Mod 4 = 0 And Text1.Text Mod 400 = 0 Then
MsgBox Text1.Text & "是闰年"
Else
MsgBox Text1.Text & "不是闰年"
End If
End Sub
Dim yea As Integer
Dim LeapYear As Boolean
yea = InputBox("请输入年号:")
If ((yea Mod 4) = 0) Then
LeapYear = ((yea Mod 100) > 0) Or ((yea Mod 400) = 0)
End If
If LeapYear Then MsgBox yea & "年是闰年。" Else MsgBox yea & "不是闰年"
Private Sub Command1_Click()dim a%text1=a
If a Mod 4 = 0 And a Mod 100 <> 0 Then
MsgBox a & "是闰年"
Else
MsgBox a & "不是闰年"
End If
End Sub