『壹』 用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
稍改改就行了