Function sizhu(birth As Date) As String
Dim A, B1, B2, F
A = Array("甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸") 'yy1+mm1+yy3
B1 = Array("子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥") 'yy2+yy4
B2 = Array("鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪") 'yy2
F = Array("小寒", "立春", "惊蛰", "清明", "立夏", "芒种", "小暑", "立秋", "白露", "寒露", "立冬", "大雪") 'i
yy = year(birth)
mm = month(birth)
dd = Day(birth)
hh = TimeSerial(Hour(birth), Minute(birth), Second(birth))
'''''''''''''''''''''''''年柱+生肖
lichun = getjq(Val(yy), 2)
If DateDiff("d", lichun, birth) >= 0 Then
yy1 = (yy - 4) Mod 10
yy2 = (yy - 4) Mod 12
Else
yy1 = (yy - 5) Mod 10
yy2 = (yy - 5) Mod 12
End If
D0 = A(yy1)
d1 = B1(yy2) & B2(yy2)
'''''''''''''''''月柱+节气
mm1 = (yy1 * 2) Mod 10
d2 = A(mm1)
D3 = B1(0) & F(11)
For i = 12 To 1 Step -1
jieqi = getjq(Val(yy), (i - 1) * 2)
If DateDiff("d", jieqi, birth) >= 0 Then
mm1 = (yy1 * 2 + i) Mod 10
d2 = A(mm1)
D3 = B1(i) & F(i - 1)
Exit For
End If
Next i
''''''''''''''''''''''日柱
birth2 = DateDiff("d", "1901-2-15", birth)
yy3 = birth2 Mod 10
If yy3 < 0 Then yy3 = yy3 + 10
yy4 = birth2 Mod 12
If yy4 < 0 Then yy4 = yy4 + 12
D4 = A(yy3)
D5 = B1(yy4)
''''''''''''''''''''' 时柱
If DateDiff("n", "23:00", hh) >= 0 Or DateDiff("n", "1:00", hh) < 0 Then
yy5 = 0
Else
yy5 = Int(DateDiff("n", "1:00", hh) / 120) + 1
End If
yy6 = (yy3 * 2 + yy5) Mod 10
D6 = A(yy6)
D7 = B1(yy5)
''''''''''''''''''''' 四柱综合
sizhu = D0 & d1 & "年 " & d2 & D3 & "月令 " & D4 & D5 & "日 " & D6 & D7 & "时"
End Function
|