2025年3月23日 星期日 甲辰(龙)年 月廿二 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > VB

VB编程:IsNumeric判断闰年

时间:05-26来源:作者:点击数:46

VB编程:IsNumeric判断闰年

运行效果:

image

运行代码:

方法一:

  • Private Sub Command1_Click()
  • Dim myYear As Boolean
  • If IsNumeric(Text1.Text) Then
  • If Text1.Text Mod 400 = 0 Then
  • myYear = True
  • ElseIf Text1.Text Mod 4 = 0 And Text1.Text Mod 100 <> 0 Then
  • myYear = True
  • Else
  • myYear = False
  • End If
  • If myYear = True Then
  • Picture1.Print Text1.Text & "是闰年!"
  • Else
  • Picture1.Print Text1.Text & "是平年!"
  • End If
  • Else
  • Picture1.Print Text1.Text & "不是数字"
  • End If
  • End Sub

方法二:

  • Public Function LeapYear(ByVal yea As Integer) As Boolean '闰年函数
  • If (yea Mod 4) = 0 Then
  • LeapYear = (yea Mod 100 > 0) Or (yea Mod 400 = 0)
  • End If
  • End Function

学习总结:

通用的步骤,可以使用函数,方便以后调用。

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门