武汉第三方催款公司:请教vb的时间函数

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 22:30:05
请问 vb中怎么能算出一年有多少天呢?
主要是为了判断闰年和平年的区别
谢谢

给你个简单的判断闰年的办法
加两句就能判断出天数了 呵呵

Dim Years As String

Years=......'得到的年份信息
If IsDate(Years & "/2/29") Then
MsgBox "该年是闰年"
Else
MsgBox "该年不是闰年"
End If

判断是否闰年不用知道有多少天
下面的例子采用非API的方法来判断一个年份是否为闰年。
闰年判断方法:能够被4或100或400整除的年份为闰年。

在一个窗体中放入一个CommandButton,然后放入下述代码

Option Explicit

Private Sub Command1_Click()

Print 2000,
Print IsLeapYearA(2000),
Print IsLeapYearB(2000)

Print 1999,
Print IsLeapYearA(1999),
Print IsLeapYearB(1999)

Print 1998,
Print IsLeapYearA(1998),
Print IsLeapYearB(1998)

Print 1997,
Print IsLeapYearA(1997),
Print IsLeapYearB(1997)

Print 1996,
Print IsLeapYearA(1996),
Print IsLeapYearB(1996)

End Sub

Function IsLeapYearA(ByVal yr As Integer) As Boolean
If ((yr Mod 4) = 0) Then
IsLeapYearA = ((yr Mod 100) > 0) Or ((yr Mod 400) = 0)
End If
End Function

Public Function IsLeapYearB(ByVal yr As Integer) As Boolean

IsLeapYearB = Day(DateSerial(yr, 2, 29)) = 29

End Function