编写一个程序,输入年份和月份,判断该年是否是闰年,并根据给出的月份判断该月是多少天?
4个回答
2013-05-24
展开全部
Private Sub Command1_Click()
Dim y As Integer, m As Integer, days As Integer
Dim leap As Boolean ' 闰年标记
If Text1.Text = "" Then MsgBox "请输入正确的年份,重试!": Exit Sub
If Text2.Text = "" Or Val(Text2.Text) < 0 Or Val(Text2.Text) > 12 Then MsgBox _
"请输入正确的月份,重试!": Exit Sub
y = Val(Text1.Text)
m = Val(Text2.Text)
If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then
leap = True ' leap的值为True时,表示该年为闰年
Else
leap = False
End IfSelect Case m
Case 1, 3, 5, 7, 8, 10, 12
days = 31
Case 4, 6, 9, 11
days = 30
Case 2
If leap Then
days = 29
Else
days = 28
End If
End Select
Label4.Caption = y & "年" & IIf(leap, "是", "不是") & "闰年," _
& Chr(13) & m & "月有" & days & "天"
Text1.SetFocus
End Sub
Dim y As Integer, m As Integer, days As Integer
Dim leap As Boolean ' 闰年标记
If Text1.Text = "" Then MsgBox "请输入正确的年份,重试!": Exit Sub
If Text2.Text = "" Or Val(Text2.Text) < 0 Or Val(Text2.Text) > 12 Then MsgBox _
"请输入正确的月份,重试!": Exit Sub
y = Val(Text1.Text)
m = Val(Text2.Text)
If (y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400 = 0) Then
leap = True ' leap的值为True时,表示该年为闰年
Else
leap = False
End IfSelect Case m
Case 1, 3, 5, 7, 8, 10, 12
days = 31
Case 4, 6, 9, 11
days = 30
Case 2
If leap Then
days = 29
Else
days = 28
End If
End Select
Label4.Caption = y & "年" & IIf(leap, "是", "不是") & "闰年," _
& Chr(13) & m & "月有" & days & "天"
Text1.SetFocus
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-05-24
展开全部
潭浩强的 C语言程序设计 一书里有例子
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询