这样:
创新互联建站是一家专注于成都网站设计、网站制作与策划设计,石城网站建设哪家好?创新互联建站做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:石城等地区。石城做网站价格咨询:18982081108
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.NET?用EXCEL中的VBA即可完成,如果需要,代码如下:
Sub test()
Dim Last As Double, SUM As Double, Resault As Double, Count As Integer
Data = Range("a1:a" Cells.Find("*", , , , 1, 2).Row)
SUM = 0: Count = 0
For i = 1 To UBound(Data, 1)
If Data(i, 1) 0 Then
If Last 0 Then
SUM = SUM + Data(i, 1) - Last
Count = Count + 1
End If
Last = Data(i, 1)
End If
Next i
Resault = SUM / Count
End Sub
注:由于统计方式比较简单,要取得需要的结果并不需要将相减后的数据放入另一数组,所以没有浪费内存去生成另一个数组。
用crystal报表,文件——新建文件——crystal报表,然后根据向导建立
int colIndex = 2;
int notNullRows = this.dataGridView1.Rows.OfTypeDataGridViewRow()
.Count(r = r.Cells[colIndex].Value != null);