登录模块加载中...
会员投稿 投稿指南 今天是:
打印本页 | 关闭窗口 | 双击滚屏 您的位置首页>>网页制作学习园地>>NET教程>>VB.Net语言>>公农历转换VB类
公农历转换VB类
来源: ‖ 作者: ‖ 点击: ‖ 时间:12-09-25 15:46:28 ‖ 【 】‖ 我要投稿
  • 网上流传很多计算公农历的源代码,很多,但是居然没有VB的,晕,
    所以。。。。。

    用法:
    以l开始的方法均为阴历,以s开始的方法均为公历
    基本的两个初使函数:
    lInitDate:用农历年月日初使化日期对象
    sInitDate: 用公历年月日初使化日期对象

    其它的方法看下面的一小段代码吧
    示例代码
    Private Sub Command1_Click()
    Dim t As clsDate
    Dim y As Long
    Dim m As Long
    Dim d As Long
    Dim st As Single
    Dim et As Single
    Dim da As Date
    Dim j As Long
    Dim ret As Long
    Set t = New clsDate
    't.sInitDate 1900, 1, 1
    t.lInitDate 2047, 5, 12, False '农历2047年5月12日,非闰月
    Debug.Print t.lYear
    If t.IsLeap = False Then
    Debug.Print t.lMonth
    Else
    Debug.Print " 闰 " & t.lMonth
    End If
    Debug.Print t.CDayStr(t.lDay) '农历日期中文大写
    Debug.Print t.GanZhi(t.lYear) '求干支
    Debug.Print t.YearAttribute(t.lYear) '农历年的属相
    Debug.Print t.sYear ' 公历年
    Debug.Print t.sMonth ' 公历月
    Debug.Print t.sDay ' 公历日
    Debug.Print t.sWeekDay '公历星期
    Debug.Print t.Era(t.sYear)' 公历纪元
    Debug.Print t.Constellation(t.sMonth, t.sDay) ' 星座
    Debug.Print "Week:" & t.wHoliday ' 按第几个星期几计算的假日
    Debug.Print "Solar" & t.sHoliday ' 按公历计算的假日
    Debug.Print "Lunar" & t.lHoliday ' 按阴历计算的假日
    Debug.Print t.lSolarTerm ' 计算节气

    '以下为速度测试,很快吧。
    st = Timer
    With t
    For y = 1900 To 2049
    For m = 1 To 12
    For d = 1 To 28
    .lInitDate y, m, d, False

    Next
    Next
    Next
    End With
    't.printf
    et = Timer
    Debug.Print et - st
    Set t = Nothing
    End Sub

    以下为代码:


    Option Explicit
    Private Type SolarHolidayStruct
    Month As Long
    Day As Long
    Recess As Long
    HolidayName As String
    End Type
    Private Type LunarHolidayStruct
    Month As Long
    Day As Long
    Recess As Long
    HolidayName As String
    End Type
    Private Type WeekHolidayStruct
    Month As Long
    WeekAtMonth As Long
    WeekDay As Long
    HolidayName As String
    End Type
    '保持属性值的局部变量
    Private mvarsYear As Long '局部复制
    Private mvarsMonth As Long '局部复制
    Private mvarsDay As Long '局部复制
    Private mvarlYear As Long '局部复制
    Private mvarlMonth As Long '局部复制
    Private mvarlDay As Long '局部复制
    Private mvarIsLeap As Boolean '局部复制
    Private Declare Function BitRight32 Lib "Bit4VB.DLL" (ByVal x As Long, ByVal num As Long) As Long
    'Private Declare Function BitRight16 Lib "Bit4VB.DLL" (ByVal x As Integer, ByVal num As Integer) As Integer
    '定义类内部用公用变量
    Private SolarMonth As Variant
    Private Gan As Variant
    Private Zhi As Variant
    Private Animals As Variant
    Private SolarTerm As Variant
    Private sTermInfo As Variant
    Private nStr1 As Variant
    Private nStr2 As Variant
    Private MonthName As Variant
    Private LunarInfo(150) As Long
    Private LunarYearDays(150) As Long
    Private sHolidayInfo() As SolarHolidayStruct
    Private lHolidayInfo() As LunarHolidayStruct
    Private wHolidayInfo() As WeekHolidayStruct
    Private mvarDate As Date '内部使用标准的日期变量

    Private Sub Class_Initialize()
    Dim tempArray As Variant
    Dim i As Long
    Dim b As Long
    Dim sFtv As Variant
    Dim lFtv As Variant
    Dim
    |<< << < 1 2 3 > >> >>|
  • 加入收藏:  加入收藏夹  | 发送给好友:  发送给好友
    责任编辑:admin
    相关文章列表
    请文明参与讨论,禁止漫骂攻击。  
    网友评论