应用思考-教育技术论坛
标题:
使用VBA判断平闰年
[打印本页]
作者:
etthink
时间:
2018-12-21 08:46
标题:
使用VBA判断平闰年
示例代码
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
复制代码
使用时一定要注意自已添加的控件名和事件名。
源文件下载:
(, 下载次数: 62)
上传
点击文件名下载附件
欢迎光临 应用思考-教育技术论坛 (http://etthink.com/)
Powered by Discuz! X3.4