dim year as integer
year=val(inputbox("输入年份"))
if (year mod 4=0 and year mod 100 <>0 ) or year mod 400=0 then
msgbox "是闰年"
else
msgbox "不是闰年"
end if
Private Sub Command1_Click()
Dim Y As Long, S As Long, nStr As String
nStr = InputBox("请输入年份:", "输入年份", 2000)
If nStr = "" Then Exit Sub
Y = Val(nStr)
S = DateDiff("d", Y & "-2-1", Y & "-3-1") '获取二月份的天数
If S = 29 Then nStr = "闰年" Else nStr = "不闰年"
MsgBox Y & ":" & nStr, vbInformation, "闰年判断"
End Sub
Dim f, d As Boolean
hf:
Y = InputBox("请输入一个四位数的年份:")
If IsNumeric(Y) Then
If Len(Y) = 4 Then
a = Y / 4
For i = 1 To Len(a)
s = Mid(a, i, 1)
If s = "" Then
f = True
Exit For
End If
Next i
z = Y / 100
For i = 1 To Len(z)
t = Mid(z, i, 1)
If t = "" Then
d = True
Exit For
End If
Next i
If f = True Or d = False Then
MsgBox "不是闰年"
Else
MsgBox "闰年"
End If
Else: GoTo gf
End If
Else: GoTo gf
End If
Exit Sub
gf:
MsgBox "格式不正确!请重新输入!"
GoTo hf
'窗体放一个text1用于输入年份,一个Command1
Private
Sub
Command1_Click()
dim
a%
a=
val(text1text)
if
(a
Mod
4
=
0
And
a
Mod
100
<>
0)
Or
a
Mod
400
=
0
then
"是闰年"
else
"不是闰年"
end
if
End
Sub
Dim year1,year As Integer
year1=InputBox("请输入年份","年份输入框")
If year1="" Then
Exit Sub
Else
year=Int(Abs(year1))
End If
If year Mod 4 = 0 And year Mod 100 <> 0 Or year Mod 400 = 0 Then
MsgBox Str(year) & "年是闰年"
Else
MsgBox Str(year) & "年是平年"
End If
Public Function IsRunnian(ByVal n As Integer) As Boolean
Dim res As Boolean
res = False
If n Mod 400 = 0 Then
res = True
End If
If (n Mod 100 <> 0) And (n Mod 4 = 0) Then
res = True
End If
Return res
End Function
以上就是关于vb中计算闰年的程序全部的内容,包括:vb中计算闰年的程序、VB编程算闰年、·在VB中如何写"设计一个解决给定一个四位数的年份,判断它是否为闰年”的算法等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)