编写一个程序,输入年份和月份,判断该年是否是闰年,并根据给出的月份判断该月是多少天?
- 提问者网友:辞取
- 2021-05-06 05:20
- 五星知识达人网友:野味小生
- 2021-05-06 06:12
潭浩强的 C语言程序设计 一书里有例子
- 1楼网友:封刀令
- 2021-05-06 06:53
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 If
Select 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