‘壹’ 用Excel,vba编程,键盘接收一个年份值,判断它是闰年还是平年怎么做
Subaa()
a=Sheet1.Cells(1,1)
IfaMod4=0Then
Sheet1.Cells(1,2)=366
Else
Sheet1.Cells(1,2)=365
EndIf
EndSub
整除4是否为零来判断闰年还是平年。
‘贰’ VBA闰年判断:输入一年份,判断其为闰年还是平年.
年份除以4,有余数为平年,没余数为闰年
‘叁’ 判断闰年vba
SubCommandButton1_Click()
Dimy,s
y=[a1]
If(yMod4=0OryMod400=0)AndyMod100<>0Then
s="闰年"
Else
s="平年"
EndIf
[a2]=y&"年是"&s
EndSub
‘肆’ 用VBA判断是否闰年
Sub CommandButton1_Click()
Dim y,s
y = [a1]
If (y Mod 4 = 0 Or y Mod 400 = 0) And y Mod 100 <> 0 Then
s= "闰年"
Else
s= "平年"
End If
[a2]=y &"年是"& s
End Sub
‘伍’ 写VB程序:判断一年是平年还是闰年
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
‘陆’ VB.NET 根据年月日判断是否为闰年或者平年!
VB.NET 判断是否为闰年或者平年!
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
闰年平年(TextBox1.Text)
End Sub
Function 闰年平年(ByVal MyString As String) As String
Dim MyDate As DateTime = Convert.ToDateTime(MyString)
Dim MyInfo As String = MyDate.Year.ToString() + "年是:"
If (DateTime.IsLeapYear(MyDate.Year) = True) Then
MyInfo += "闰年。"
Else
MyInfo += "平年。"
End If
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return 1
End Function
End Class
‘柒’ VBA计算平闰年,如何修改如图的代码使得可以使n为任意数都可判断 感谢!!
Subtest()
Dimn,s
n=InputBox("请输入年份:")
If(nMod4=0OrnMod400=0)AndnMod100<>0Then
s="闰年"
Else
s="平年"
EndIf
MsgBoxn&"年是"&s
EndSub
‘捌’ VB编程,求年份是闰年还是平年。下面图中所标出的错哪了求指出和改正,谢谢。
Mod
400
以后就不需要
Mod
100
了啊!
Private
Function
查询闰年(ByVal
年份
As
Integer)
As
StringBuilder
If
(年份
Mod
400
=
0)
OrElse
(年份
Mod
100
<>
0
And
年份
Mod
4
=
0)
Then
Return
New
StringBuilder("您输入的年份
"
&
年份
&
"
是闰年。")
Else
Return
New
StringBuilder("您输入的年份
"
&
年份
&
"
不是闰年。")
End
If
End
Function
这是
.NET
的,6.0
稍改改就行了