
1900年到2200年之间的所有闰年显示在窗体中的命令:
dim i as integer
for i = 1900 to 2200
if (i mod 4 = 0 and i mod 100 <> 0) or (i mod 400 = 0) then
lstadditem i
end if
next i
采用的VB的变量进行的命令。
扩展资料:
VB 编写程序对变量进行的赋值:
VB变量是指在运行时其值可以被改变的量不同于常量,变量是可以多次赋值的,因此此变量常用于保存程序中的临时数据。变量在程序中使用是非常频繁的,对此变量的声明和使用应熟练掌握。
1、变量必须是以字母、汉字开头并且以字母、汉字、数字、下划线组成的字符串。最后一个字符可以是类型说明符,变量名中不能有空格。
2、变量名不能包含+ - / !@ # ¥ ?小数点 等字符,且长度不能超过255。
3、不能用 Visual Basic 的保留字(例如End、Len、Sub等)作为变量名,但可以把保留字嵌入变量名中,同时变量名也不能是末尾带有说明符的保留字。
4、Visual Basic 不区分变量名和其他名字中字母的大小写,但习惯上,符号常量一般用大写字母定义。在 Visual Basic 中执行应用程序期间,用变量临时存储数值。变量有名字(用来引用变量所包含的值的词)和数据类型(确定变量能够存储的数据的种类)。
参考资料来源:百度百科-VB变量
Function isRunNian(y As Integer) As Boolean
isRunNian = Day(DateSerial(y, 3, 0)) = 29
End Function
以上代码是通过判断2月的最后一天是否29日来判断闰年的
Function isRunNian(y As Integer) As BooleanisRunNian = DatePart("y", DateSerial(y, 12, 31)) = 366
End Function
以上代码是通过判断该年的总天数是否为366天来判断闰年的
Function isRunNian(y As Integer) As BooleanisRunNian = (y Mod 4 = 0 And y Mod 100 <> 0) Or y Mod 400 = 0
End Function
以上代码是根据年份能被4整除但不能被100整除、或者能被400整除来判断的
需要说明的是:以上第三种属于学院派标准解法,而前面两种属于民间高手解法
用VB做万年历,非常关键点就是农历写法,参考代码如下:
#Region " 返回农历 "
'返回农历
'cCalendarMaxSupportedDateTime 返回支持的最大日期,即2101-1-28
'cCalendarMinSupportedDateTime 返回支持的最小日期,即190-2-19
Private cCalendar As New SystemGlobalizationChineseLunisolarCalendar
Public Function PubFunGet_CNDate(ByVal sDateTime As Date) As String
cCalendar = New SystemGlobalizationChineseLunisolarCalendar
Dim lyear As Integer = cCalendarGetYear(sDateTime)
Dim lmonth As Integer = cCalendarGetMonth(sDateTime)
Dim lday As Integer = cCalendarGetDayOfMonth(sDateTime)
Dim lweek As Integer = cCalendarGetDayOfWeek(sDateTime)
'获取闰月, 0 则表示没有闰月
Dim leapMonth As Integer = cCalendarGetLeapMonth(lyear)
Dim isleap As Boolean = False
If (leapMonth > 0) Then
If (leapMonth = lmonth) Then
'闰月
isleap = True
lmonth = lmonth - 1
ElseIf (lmonth > leapMonth) Then
lmonth = lmonth - 1
End If
End If
Return StringConcat(GetLunisolarYear(lyear), IIf(isleap = True, "闰年", "年"), GetLunisolarMonth(lmonth), "月", GetLunisolarDay(lday))
End Function
'十天干
Private tiangan As String() = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}
'十二地支
Private dizhi As String() = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}
'十二生肖
Private shengxiao As String() = {"鼠", "牛", "虎", "免", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}
'农历月
Private months As String() = {"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二(腊)"}
'农历日
Private days1 As String() = {"初", "十", "廿", "三"}
Private days As String() = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}
'返回农历年(天干 地支 生肖)
Private Function GetLunisolarYear(ByVal year As Integer) As String
GetLunisolarYear = ""
If (year > 3) Then
Dim tgIndex As Integer = (year - 4) Mod 10
Dim dzIndex As Integer = (year - 4) Mod 12
Return tiangan(tgIndex) & dizhi(dzIndex) & "[" & shengxiao(dzIndex) & "]"
End If
'无效的年份!
End Function
'返回生肖
Private Function GetShengXiao(ByVal sDateTime As Date) As String
Return shengxiao(cCalendarGetTerrestrialBranch(cCalendarGetSexagenaryYear(sDateTime)) - 1)
End Function
'返回农历月
Private Function GetLunisolarMonth(ByVal month As Integer) As String
GetLunisolarMonth = ""
If (month < 13 AndAlso month > 0) Then
Return months(month - 1)
End If
'无效的月份!
End Function
'返回农历日
Private Function GetLunisolarDay(ByVal day As Integer) As String
GetLunisolarDay = ""
If (day > 0 AndAlso day < 32) Then
If (day <> 20 AndAlso day <> 30) Then
Return StringConcat(days1((day - 1) \ 10), days((day - 1) Mod 10))
Else
Return StringConcat(days((day - 1) \ 10), days1(1))
End If
End If
'无效的日!
End Function
#End Region
我只给出一个判断是否为闰年的算法,致于季节,多少天这个问题你可以自己解决了
int leapyear(int year) //判断某年是否闰年 闰年返回1,平年返回0
{
if ((year%400==0) || (year%100!=0) && (year%4==0))
return 1;
else
return 0;
}
以上就是关于用 VB 编写程序将1900年到2200年之间的所有闰年显示在窗体中一列表框中全部的内容,包括:用 VB 编写程序将1900年到2200年之间的所有闰年显示在窗体中一列表框中、用vb编写一个函数实现闰年的判断,形参为任意年数,如为闰年,函数返回结果为tru、用vb编写万年历小程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)