vbnet判断闰年 web判断闰年
输入年份,编程判断是否为闰年 VB.NET
Private Sub Command1_Click()
创新互联主营如东网站建设的网络公司,主营网站建设方案,app软件定制开发,如东h5微信平台小程序开发搭建,如东网站营销推广欢迎如东等地区企业咨询
Dim year As Integer, y As Integer
year = Val(InputBox("要判断的年份是:"))
Call runnian(year, y)
If y = 1 Then
Print Str(year); Spc(2); "键卜年是闰年!"
Else
Print Str(year); Spc(2); "年茄镇不是闰年!"
End If
End Sub
Public Sub runnian(n As Integer, x As Integer)
Dim leap As Integer
If n Mod 400 = 0 Then
leap = 1
ElseIf n Mod 4 = 0 And n Mod 100 稿纳穗 0 Then
leap = 1
Else
leap = 0
End If
x = leap
End Sub
在vb点虐 中,如何计算出2000-2100年之间的闰年?输出到文本框,并统计输出闰年的个数?主要是统计个数
这样:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim leapyears() As Integer = GetLeapYears(2000, 2100)
Dim str As String
Try
Dim count As Integer = UBound(leapyears) + 1
str = "闰年个数:" + count.ToString
For i = 0 To UBound(leapyears)
str += " " + leapyears(i).ToString
Next
TextBox1.Text = str
Catch ex As Exception
End Try
End Sub
''' summary
''' 获取指定年份区间中所有闰年组成的数组
''' /summary
''' param name="StartYear"起始年饥配份/param
''' param name="EndYear"结束年份/param
''' returns/returns
''' remarks/remarks
Private Function GetLeapYears(StartYear As Integer, EndYear As Integer) As Integer()
Dim leapyears() As Integer = Nothing
Dim index As Integer = 0
For i = StartYear To EndYear
If (i Mod 400 = 0) Or (i Mod 4 = 0 And i Mod 100 0) Then
ReDim Preserve leapyears(index)
leapyears(index) = i
index += 1
End If
Next
Return leapyears
End Function
扩展资料:
注意事项
DateSerial返回包含指定的年、月、日的 Variant (Date)。
语法:DateSerial(year, month, day)
Private Function MonthToLeapYear(ByVal Yea As Integer) As Boolean
MonthToLeapYear = Day(DateSerial(Yea, 2, 29)) = 29
End Function
Private Sub Command1_Click()
If Len(Text1.Text) = 4 Then
If MonthToLeapYear(Text1.Text) = True Then
Print Text1.Text "年是闰年"
Else
Print Text1.Text "年是平年"
End If
Else
Print "错误:请输入正确的年份!"
End If
End Sub
在VB.NET中进行日期处理时,避免手工判断或计算是个好脊桐主意,因为手工计算由于代码的质量问题可能不准确。可以使用.NET提供的类的功樱肢坦能进行日期处理。
例如,如果需要判断给定的某年是否闰年,可以使用VB.NET的IsLeapYear函数。下面是如何使用该函数的一个例子:
Private Sub LeapYearCheck()
Dim bLeapYear AsBoolean
bLeapYear = Date.IsLeapYear(Now.Year)
MessageBox.Show(bLeapYear)
bLeapYear = Date.IsLeapYear(2004)
MessageBox.Show(bLeapYear)
End Sub
VB编程 判断闰年
Private Sub Form_Click()
Dim a As Integer
a 漏碰= Val(InputBox("输入年份"))
If a Mod 400 = 0 Then
Print "是瑞年"
ElseIf a Mod 4 = 0 And a Mod 100 0 Then
Print "是瑞此启年 "
Else
Print "返扒谈不是瑞年"
End If
End Sub
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
分享标题:vbnet判断闰年 web判断闰年
分享地址:http://pwwzsj.com/article/ddpjhsh.html