示例代码
- Sub 判断闰年()
- Dim year As Integer '用于保存输入的年份
- year = CInt(InputBox("请输入需要判断的年份:", "判断闰年")) '输入年份
- If year Mod 4 = 0 And year Mod 100 <> 0 Then
- MsgBox "" & "是一个闰年", vbOKOnly, "判断闰年"
- Else
- If year Mod 100 = 0 And year Mod 400 = 0 Then
- MsgBox "" & "是一个闰年", vbOKOnly, "判断闰年"
- Else
- MsgBox "" & "不是一个闰年", vbOKOnly, "判断闰年"
- End If
- End If
- End Sub
复制代码 如果在PPT中使用控件比如文本框来生成或输入年份,修改为:
- Dim year As Integer
- Private Sub CommandButton1_Click()
- year = Rnd * 1000 + 2000
- TextBox1.Text = year
- End Sub
- Private Sub CommandButton2_Click()
- year = Int(TextBox1.Text)
- If year Mod 4 = 0 And year Mod 100 <> 0 Then
- MsgBox (TextBox1.Text + "年" + "是闰年")
- Else
- If year Mod 100 = 0 And year Mod 400 = 0 Then
- MsgBox (TextBox1.Text + "年" + "是闰年")
- Else
- MsgBox (TextBox1.Text + "年" + "不是闰年")
- End If
- End If
- End Sub
复制代码 使用时一定要注意自已添加的控件名和事件名。
源文件下载:
判断闰年.rar
(187.41 KB, 下载次数: 55)
|