Last active
February 18, 2024 09:18
-
-
Save touchiep/689d68726b17ca2d2bc2a5ffb1d33238 to your computer and use it in GitHub Desktop.
[VBA][Excel] สูตรสำหรับแปลงวันที่ปกติเป็นวันที่ทางจันทรคติล้านนา สำหรับใช้กับ Excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Function LNLDate(iDate As Date, Optional DispNumber As Integer = 0, Optional Zodiac As Integer = 0, Optional Era As Integer = 0, Optional DhammaDay As Boolean = False, Optional NumberOnly As Boolean = False) | |
'LNLDate = Lanna Lunar Date สำหรับแสดงผลวันที่แบบจันทรคติล้านนา | |
'แปลงวันที่แบบสุริยคติให้เป็นจันทรคติ | |
'Copyright 2022 and later by Pongsathorn Sraouthai | |
'Version 2.0 Optimized for faster calculation | |
'Inspired by Loy's calculation | |
'ตัวแปร | |
'iDate = วันที่ ที่ใช้อ้างอิง | |
'DispNumber = แสดงผลตัวเลข 0 เลขอารบิก 1 เลขไทย 2 เลขโหราล้านนา | |
'Zodiac = แสดงชื่อปี 0 ไม่เสดง 1 ปีนักษัตรไทย 2 ปีหนไท | |
'Era = แสดงศักราช 0 ไม่แสดง 1 พุทธศักราช 2 จุลศักราช | |
'DhammaDay = ถ้าเป็น True แสดงธรรมจักรในวันพระ | |
Dim DayInYear | |
Dim BeginDate As Date | |
Dim PrevYear, CurrYear | |
Dim i As Integer, j As Integer | |
Dim ThM, DofY, DofM, RDayPrev, DayOfYear, DayFromOne, NbLDayYear, ThS, ThZ, ThH, RDayLY, ThD1, ThD2, TmpD, ThK, jD | |
Dim sDate(1 To 56) As Date, CYear | |
'ตรวจสอบว่าเป็นปีที่รองรับการคำนวณได้หรือไม่ | |
If year(iDate) < 1903 Or year(iDate) > 2460 Then | |
LNLDate = "ไม่รองรับ" | |
Exit Function | |
End If | |
'เลือก begin date ให้ใกล้สุดเพื่อที่จะได้ทำงานไวสุด | |
sDate(1) = DateSerial(1902, 10, 2) | |
sDate(2) = DateSerial(1912, 10, 10) | |
sDate(3) = DateSerial(1922, 9, 21) | |
sDate(4) = DateSerial(1932, 9, 29) | |
sDate(5) = DateSerial(1942, 10, 9) | |
sDate(6) = DateSerial(1952, 9, 18) | |
sDate(7) = DateSerial(1962, 9, 28) | |
sDate(8) = DateSerial(1972, 10, 7) | |
sDate(9) = DateSerial(1982, 9, 17) | |
sDate(10) = DateSerial(1992, 9, 26) | |
sDate(11) = DateSerial(2002, 10, 6) | |
sDate(12) = DateSerial(2012, 9, 15) | |
sDate(13) = DateSerial(2022, 9, 25) | |
sDate(14) = DateSerial(2032, 10, 4) | |
sDate(15) = DateSerial(2042, 10, 14) | |
sDate(16) = DateSerial(2052, 9, 23) | |
sDate(17) = DateSerial(2062, 10, 3) | |
sDate(18) = DateSerial(2072, 10, 11) | |
sDate(19) = DateSerial(2082, 9, 22) | |
sDate(20) = DateSerial(2092, 9, 30) | |
sDate(21) = DateSerial(2102, 10, 11) | |
sDate(22) = DateSerial(2112, 9, 20) | |
sDate(23) = DateSerial(2122, 9, 30) | |
sDate(24) = DateSerial(2132, 10, 9) | |
sDate(25) = DateSerial(2142, 9, 19) | |
sDate(26) = DateSerial(2152, 9, 28) | |
sDate(27) = DateSerial(2162, 10, 8) | |
sDate(28) = DateSerial(2172, 9, 17) | |
sDate(29) = DateSerial(2182, 9, 27) | |
sDate(30) = DateSerial(2192, 10, 6) | |
sDate(31) = DateSerial(2202, 10, 17) | |
sDate(32) = DateSerial(2212, 9, 26) | |
sDate(33) = DateSerial(2222, 10, 6) | |
sDate(34) = DateSerial(2232, 10, 14) | |
sDate(35) = DateSerial(2242, 9, 25) | |
sDate(36) = DateSerial(2252, 10, 3) | |
sDate(37) = DateSerial(2262, 10, 13) | |
sDate(38) = DateSerial(2272, 9, 22) | |
sDate(39) = DateSerial(2282, 10, 2) | |
sDate(40) = DateSerial(2292, 10, 11) | |
sDate(41) = DateSerial(2302, 9, 22) | |
sDate(42) = DateSerial(2312, 10, 1) | |
sDate(43) = DateSerial(2322, 10, 11) | |
sDate(44) = DateSerial(2332, 9, 20) | |
sDate(45) = DateSerial(2342, 9, 30) | |
sDate(46) = DateSerial(2352, 10, 9) | |
sDate(47) = DateSerial(2362, 10, 19) | |
sDate(48) = DateSerial(2372, 9, 28) | |
sDate(49) = DateSerial(2382, 10, 8) | |
sDate(50) = DateSerial(2392, 10, 16) | |
sDate(51) = DateSerial(2402, 9, 27) | |
sDate(52) = DateSerial(2412, 10, 5) | |
sDate(53) = DateSerial(2422, 10, 15) | |
sDate(54) = DateSerial(2432, 9, 25) | |
sDate(55) = DateSerial(2442, 10, 4) | |
sDate(56) = DateSerial(2452, 10, 13) | |
CYear = year(iDate) - 1 | |
Select Case CYear | |
Case Is > 2452 | |
BeginDate = sDate(56) | |
Case Is > 2442 | |
BeginDate = sDate(55) | |
Case Is > 2432 | |
BeginDate = sDate(54) | |
Case Is > 2422 | |
BeginDate = sDate(53) | |
Case Is > 2412 | |
BeginDate = sDate(52) | |
Case Is > 2402 | |
BeginDate = sDate(51) | |
Case Is > 2392 | |
BeginDate = sDate(50) | |
Case Is > 2382 | |
BeginDate = sDate(49) | |
Case Is > 2372 | |
BeginDate = sDate(48) | |
Case Is > 2362 | |
BeginDate = sDate(47) | |
Case Is > 2352 | |
BeginDate = sDate(46) | |
Case Is > 2342 | |
BeginDate = sDate(45) | |
Case Is > 2332 | |
BeginDate = sDate(44) | |
Case Is > 2322 | |
BeginDate = sDate(43) | |
Case Is > 2312 | |
BeginDate = sDate(42) | |
Case Is > 2302 | |
BeginDate = sDate(41) | |
Case Is > 2292 | |
BeginDate = sDate(40) | |
Case Is > 2282 | |
BeginDate = sDate(39) | |
Case Is > 2272 | |
BeginDate = sDate(38) | |
Case Is > 2262 | |
BeginDate = sDate(37) | |
Case Is > 2252 | |
BeginDate = sDate(36) | |
Case Is > 2242 | |
BeginDate = sDate(35) | |
Case Is > 2232 | |
BeginDate = sDate(34) | |
Case Is > 2222 | |
BeginDate = sDate(33) | |
Case Is > 2212 | |
BeginDate = sDate(32) | |
Case Is > 2202 | |
BeginDate = sDate(31) | |
Case Is > 2192 | |
BeginDate = sDate(30) | |
Case Is > 2182 | |
BeginDate = sDate(29) | |
Case Is > 2172 | |
BeginDate = sDate(28) | |
Case Is > 2162 | |
BeginDate = sDate(27) | |
Case Is > 2152 | |
BeginDate = sDate(26) | |
Case Is > 2142 | |
BeginDate = sDate(25) | |
Case Is > 2132 | |
BeginDate = sDate(24) | |
Case Is > 2122 | |
BeginDate = sDate(23) | |
Case Is > 2112 | |
BeginDate = sDate(22) | |
Case Is > 2102 | |
BeginDate = sDate(21) | |
Case Is > 2092 | |
BeginDate = sDate(20) | |
Case Is > 2082 | |
BeginDate = sDate(19) | |
Case Is > 2072 | |
BeginDate = sDate(18) | |
Case Is > 2062 | |
BeginDate = sDate(17) | |
Case Is > 2052 | |
BeginDate = sDate(16) | |
Case Is > 2042 | |
BeginDate = sDate(15) | |
Case Is > 2032 | |
BeginDate = sDate(14) | |
Case Is > 2022 | |
BeginDate = sDate(13) | |
Case Is > 2012 | |
BeginDate = sDate(12) | |
Case Is > 2002 | |
BeginDate = sDate(11) | |
Case Is > 1992 | |
BeginDate = sDate(10) | |
Case Is > 1982 | |
BeginDate = sDate(9) | |
Case Is > 1972 | |
BeginDate = sDate(8) | |
Case Is > 1962 | |
BeginDate = sDate(7) | |
Case Is > 1952 | |
BeginDate = sDate(6) | |
Case Is > 1942 | |
BeginDate = sDate(5) | |
Case Is > 1932 | |
BeginDate = sDate(4) | |
Case Is > 1922 | |
BeginDate = sDate(3) | |
Case Is > 1912 | |
BeginDate = sDate(2) | |
Case Is > 1902 | |
BeginDate = sDate(1) | |
End Select | |
'นับวารถึงปีก่อนหน้าปีปัจจุบัน | |
For i = year(BeginDate) + 1 To year(iDate) - 1 | |
DayInYear = LDayInYear(i) | |
PrevYear = DateAdd("d", DayInYear, BeginDate) | |
BeginDate = PrevYear | |
Next i | |
RDayPrev = DateDiff("d", PrevYear, DateSerial(year(PrevYear), 12, 31)) 'จำนวนวารที่เหลืออยู่ของปี นับจาก ขึ้น 1 ค่ำเดือน 1 | |
DayOfYear = DateDiff("d", DateSerial(year(iDate), 1, 1), iDate) 'จำนวนวันของปีที่ถึงวันที่ที่กำหนด | |
DayFromOne = RDayPrev + DayOfYear + 1 'จำนวนวารจากขึ้น ๑ ค่ำ เดือน ๑ + จำนวนวารที่เหลือในปีถัดไป | |
NbLDayYear = LDayInYear(year(iDate)) 'จำนวนวารของปี | |
'จำแนกชนิดของปีปัจจุบัน | |
Select Case NbLDayYear | |
Case 354 'ปีปกติ | |
RDayLY = RDayPrev + NODIYear(year(iDate)) | |
DofY = DayFromOne | |
For j = 1 To 16 | |
ThM = j | |
Select Case j | |
Case 1 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 2 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 3 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 4 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 5 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 6 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 7 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 8 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 9 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 10 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 11 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 12 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 13 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 14 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 15 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 16 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case Else | |
End Select | |
Next | |
'ช่วงขึ้นปีใหม่ของราชการ | |
If ThM > 12 Then | |
ThM = ThM - 12 | |
ThZ = 1 | |
Else | |
ThZ = 0 | |
End If | |
If NumberOnly = True Then | |
If DofY > 15 Then | |
ThS = "-" | |
DofY = DofY - 15 | |
Else | |
ThS = "+" | |
End If | |
LNLDate = ThS & Format(DofY, "00") & Format(ThM, "00") | |
Else | |
If DofY > 15 Then | |
ThS = " แรม " | |
DofY = DofY - 15 | |
Else | |
ThS = " ออก " | |
End If | |
LNLDate = "เดือน " & ThM & ThS & DofY & " ค่ำ" | |
End If | |
Case 355 'ปีอธิกวาร | |
RDayLY = RDayPrev + NODIYear(year(iDate)) | |
DofY = DayFromOne | |
For j = 1 To 16 | |
ThM = j | |
Select Case j | |
Case 1 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 2 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 3 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 4 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 5 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 6 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 7 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 8 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 9 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 10 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 11 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 12 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 13 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 14 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 15 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 16 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case Else | |
End Select | |
Next | |
If ThM > 12 Then | |
ThM = ThM - 12 | |
ThZ = 1 | |
Else | |
ThZ = 0 | |
End If | |
If NumberOnly = True Then | |
If DofY > 15 Then | |
ThS = "-" | |
DofY = DofY - 15 | |
Else | |
ThS = "+" | |
End If | |
LNLDate = ThS & Format(DofY, "00") & Format(ThM, "00") | |
Else | |
If DofY > 15 Then | |
ThS = " แรม " | |
DofY = DofY - 15 | |
Else | |
ThS = " ออก " | |
End If | |
LNLDate = "เดือน " & ThM & ThS & DofY & " ค่ำ" | |
End If | |
Case 384 'ปีอธิกมาส | |
RDayLY = RDayPrev + NODIYear(year(iDate)) | |
DofY = DayFromOne | |
For j = 1 To 17 | |
ThM = j | |
Select Case j | |
Case 1 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 2 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 3 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 4 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 5 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 6 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 7 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 8 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 9 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 10 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 11 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 12 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 13 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 14 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 15 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case 16 | |
If DofY <= 29 And DofY > 0 Then Exit For Else DofY = DofY - 29 | |
Case 17 | |
If DofY <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
Case Else | |
End Select | |
Next | |
If ThM > 13 Then | |
ThM = ThM - 13 | |
ThZ = 1 | |
Else | |
ThZ = 0 | |
End If | |
Select Case ThM | |
Case 11 | |
ThM = 10 | |
Case 12 | |
ThM = 11 | |
Case 13 | |
ThM = 12 | |
End Select | |
If NumberOnly = True Then | |
If DofY > 15 Then | |
ThS = "-" | |
DofY = DofY - 15 | |
Else | |
ThS = "+" | |
End If | |
LNLDate = ThS & Format(DofY, "00") & Format(ThM, "00") | |
'LNLDate = ThS & DofY & " ค่ำ เดือน " & ThM | |
Else | |
If DofY > 15 Then | |
ThS = " แรม " | |
DofY = DofY - 15 | |
Else | |
ThS = " ออก " | |
End If | |
LNLDate = "เดือน " & ThM & ThS & DofY & " ค่ำ" | |
End If | |
End Select | |
'แสดงตัวเลข | |
Select Case DispNumber | |
Case 0 | |
LNLDate = LNLDate 'เลขอารบิก | |
Case 1 | |
LNLDate = W2TH(CStr(LNLDate)) 'เลขไทย | |
Case 2 | |
LNLDate = W2LN(CStr(LNLDate)) 'เลขโหรา | |
End Select | |
'แสดงชื่อปี | |
Select Case Zodiac | |
Case 1 | |
LNLDate = LNLDate & " ปี" & ThZodiac(year(iDate)) | |
Case 2 | |
jD = ThLSokDay(year(iDate), 2) | |
Select Case iDate | |
Case Is < jD | |
LNLDate = LNLDate & " ปี" & ThHonThai(year(iDate) - 1) | |
Case Is >= jD | |
LNLDate = LNLDate & " ปี" & ThHonThai(year(iDate)) | |
End Select | |
Case Else | |
End Select | |
'แสดงปีศักราช ถ้าตัวเลือก Era เป็น 1-5 | |
Select Case Era | |
Case 1 | |
Select Case DispNumber | |
Case 2 | |
LNLDate = W2LN(LNLDate & " พุทธศักราช " & year(iDate) + 543) | |
Case 1 | |
LNLDate = W2TH(LNLDate & " พุทธศักราช " & year(iDate) + 543) | |
Case 0 | |
LNLDate = LNLDate & " พุทธศักราช " & year(iDate) + 543 | |
End Select | |
Case 2 | |
jD = ThLSokDay(year(iDate), 2) | |
Select Case iDate | |
Case Is < jD | |
Select Case DispNumber | |
Case 2 | |
LNLDate = W2TH(LNLDate & " จุลศักราช " & year(iDate) - 639) | |
Case 1 | |
LNLDate = W2TH(LNLDate & " จุลศักราช " & year(iDate) - 639) | |
Case 0 | |
LNLDate = LNLDate & " จุลศักราช " & year(iDate) - 639 | |
End Select | |
Case Is >= jD | |
Select Case DispNumber | |
Case 2 | |
LNLDate = W2TH(LNLDate & " จุลศักราช " & year(iDate) - 638) | |
Case 1 | |
LNLDate = W2TH(LNLDate & " จุลศักราช " & year(iDate) - 638) | |
Case 0 | |
LNLDate = LNLDate & " จุลศักราช " & year(iDate) - 638 | |
End Select | |
End Select | |
Case Else | |
End Select | |
'แสดงธรรมจักรในวันพระ | |
If DhammaDay = True Then | |
LNLDate = LNLDate & LNDmDay(iDate) | |
End If | |
If NumberOnly = True Then | |
'แสดงข้อมูลในลักษณะตัวเลข | |
'000000 | |
'^^ 10 = ข้างขึ้น 00 = ข้างแรม | |
' ^^ = ค่ำ | |
' ^^ = เดือน | |
LNLDate = Replace(LNLDate, "+", "10") | |
LNLDate = Replace(LNLDate, "-", "00") | |
End If | |
LNLDate = Trim(LNLDate) | |
End Function | |
Function W2LN(strInput As String) As String | |
'Convert Western number to Lanna Hora number | |
Dim numberArray | |
Dim i As Long | |
numberArray = Array("0", ChrW(6784), _ | |
"1", ChrW(6785), _ | |
"2", ChrW(6786), _ | |
"3", ChrW(6787), _ | |
"4", ChrW(6788), _ | |
"5", ChrW(6789), _ | |
"6", ChrW(6790), _ | |
"7", ChrW(6791), _ | |
"8", ChrW(6792), _ | |
"9", ChrW(6793)) | |
W2LN = strInput | |
For i = 0 To 18 Step 2 | |
W2LN = Replace(W2LN, numberArray(i), numberArray(i + 1)) | |
Next i | |
End Function | |
Function LNDmDay(iDate As Date) | |
'สำหรับแสดงวันพระ แบบล้านนา | |
'7446 ขึ้น 8 | |
'7447 แรม 8 | |
'9675 ขึ้น15 | |
'9679 แรม14-15 | |
'9784 ธรรมจักร | |
Dim nDate, n1, n2, n3 | |
nDate = LNLDate(iDate, , , , , True) | |
n1 = Mid(nDate, 1, 1) | |
n2 = Mid(nDate, 3, 2) | |
n3 = Mid(nDate, 5, 2) | |
Select Case n1 | |
Case "1" | |
Select Case n2 | |
Case "08" | |
LNDmDay = ChrW(9784) | |
Case "15" | |
LNDmDay = ChrW(9784) | |
Case Else | |
LNDmDay = "" | |
End Select | |
Case "0" | |
Select Case n2 | |
Case "08" | |
LNDmDay = ChrW(9784) | |
Case "14" | |
Select Case LDayInYear(year(iDate)) | |
Case 354 | |
If val(n3) Mod 2 = 1 Then LNDmDay = ChrW(9784) Else LNDmDay = "" | |
Case 355 | |
If val(n3) Mod 2 = 1 And val(n3) <> 9 Then LNDmDay = ChrW(9784) Else LNDmDay = "" | |
Case 384 | |
If val(n3) Mod 2 = 1 Then LNDmDay = ChrW(9784) Else LNDmDay = "" | |
End Select | |
Case "15" | |
LNDmDay = ChrW(9784) | |
Case Else | |
LNDmDay = "" | |
End Select | |
End Select | |
End Function | |
Function ThLSokDay(iYear As Integer, Optional oType As Integer = 0) | |
'ค้นหาวันเถลิงศกในปี ค.ศ. ที่ระบุ | |
Dim JYear | |
Dim result, result2 | |
Dim d1, d2, d3, d4, d5, d6 | |
JYear = iYear - 638 'แปลงเป็นจุลศักราช | |
d1 = JYear * 0.25875 | |
d2 = d1 + Int(JYear / 100 + 0.38) | |
d3 = d2 - Int(JYear / 4 + 0.5) | |
d4 = d3 - Int(JYear / 400 + 0.595) | |
d5 = d4 - 5.53375 | |
d6 = Abs(d5 - Int(d5)) | |
result = DateSerial(iYear, 4, Int(d5)) | |
result = result + d6 | |
Select Case oType | |
Case 0 'แสดงเป็นวันที่ | |
ThLSokDay = result | |
Case 1 'แสดงเฉพาะเลขวันที่ | |
ThLSokDay = Int(d5) | |
Case 2 'ตัดทศนิยมออก | |
ThLSokDay = Int(result) | |
End Select | |
End Function | |
Public Function ThHonThai(iNumber As Integer, Optional oType As String = "y") | |
'สำหรับแสดงปีแบบหนไท | |
'oType y = สำหรับใช้กับปี (ค.ศ.) d = สำหรับใช้กับวัน | |
Dim mY(1 To 10), sY(1 To 12) | |
Dim result, r1, r2, d1, d2, result2 | |
mY(1) = "กาบ" '6 | |
mY(2) = "ดับ" '7 | |
mY(3) = "รวาย" '8 | |
mY(4) = "เมือง" '9 | |
mY(5) = "เปิก" '10 | |
mY(6) = "กัด" '1 | |
mY(7) = "กด" '2 | |
mY(8) = "ร้วง" '3 | |
mY(9) = "เต่า" '4 | |
mY(10) = "ก่า" '5 | |
sY(1) = "ใจ้" '2 | |
sY(2) = "เป้า" '3 | |
sY(3) = "ยี" '4 | |
sY(4) = "เหม้า" '5 | |
sY(5) = "สี" '6 | |
sY(6) = "ใส้" '7 | |
sY(7) = "สะง้า" '8 | |
sY(8) = "เม็ด" '9 | |
sY(9) = "สัน" '10 | |
sY(10) = "เร้า" '11 | |
sY(11) = "เส็ด" '12 | |
sY(12) = "ใค้" '1 | |
'result = iYear - 638 | |
r1 = XLMod(iNumber, 10) | |
If r1 - 3 < 1 Then | |
r1 = r1 - 3 + 10 | |
Else | |
r1 = r1 - 3 | |
End If | |
r2 = XLMod(iNumber, 12) | |
If r2 - 3 < 1 Then | |
r2 = r2 - 3 + 12 | |
Else | |
r2 = r2 - 3 | |
End If | |
result = mY(r1) & sY(r2) | |
d1 = XLMod(iNumber, 10) | |
If d1 = 0 Then d1 = 10 | |
d2 = XLMod(iNumber, 12) | |
If d2 = 0 Then d2 = 12 | |
result2 = mY(d1) & sY(d2) | |
Select Case oType | |
Case "d" | |
ThHonThai = result2 | |
Case "y" | |
ThHonThai = result | |
End Select | |
End Function | |
Private Function XLMod(a, b) | |
' This attempts to mimic the Excel MOD function | |
XLMod = a - b * Int(a / b) | |
End Function | |
Public Function AthikaMas(iYear As Integer) As Boolean | |
'AthikaMas calculation | |
'Return True if the specified year is AthikaMas. | |
'Inspired by Loy's Calculation | |
Dim Athi | |
Athi = XLMod((iYear - 78) - 0.45222, 2.7118886) | |
If Athi < 1 Then | |
AthikaMas = True | |
Else | |
AthikaMas = False | |
End If | |
End Function | |
Public Function AthikaVar(iYear As Integer) As Boolean | |
'AthikaVar calculation | |
'Return True if the specified year is AthikaVar. | |
'Inspired by Loy's Calculation | |
Dim CutOff | |
If AthikaMas(iYear) = True Then | |
AthikaVar = False | |
Else | |
If AthikaMas(iYear + 1) = True Then 'ตรวสอบปีถัดไปว่าเป็นอธิกมาสหรือไม่ | |
CutOff = 1.69501433191599E-02 'ปีถัดไปเป็น อธิกมาส | |
Else | |
CutOff = -1.42223099315486E-02 'ปีถัดไปเป็น ปกติ | |
End If | |
If Deviation(iYear) > CutOff Then 'ถ้าค่าเบี่ยงเบนสูงกว่าค่า cutoff จะเป็นปีอธิกวาร | |
AthikaVar = True | |
Else | |
AthikaVar = False | |
End If | |
End If | |
End Function | |
Private Function Deviation(iYear As Integer) | |
'The Deviation calculation for AthikaVar from year 1901 to 2460 | |
'Copyright 2022 and later by Pongsathorn Sraouthai | |
'Inspired by Loy's Calculation | |
Dim FDev, Fyear 'The deviation value from year 1901, Buddist Era 2444 | |
Dim CurrDev, lastDev | |
Dim i As Integer, j As Integer | |
Dim StartY(1 To 112, 1 To 2) | |
StartY(1, 1) = 1901 | |
StartY(2, 1) = 1906 | |
StartY(3, 1) = 1911 | |
StartY(4, 1) = 1916 | |
StartY(5, 1) = 1921 | |
StartY(6, 1) = 1926 | |
StartY(7, 1) = 1931 | |
StartY(8, 1) = 1936 | |
StartY(9, 1) = 1941 | |
StartY(10, 1) = 1946 | |
StartY(11, 1) = 1951 | |
StartY(12, 1) = 1956 | |
StartY(13, 1) = 1961 | |
StartY(14, 1) = 1966 | |
StartY(15, 1) = 1971 | |
StartY(16, 1) = 1976 | |
StartY(17, 1) = 1981 | |
StartY(18, 1) = 1986 | |
StartY(19, 1) = 1991 | |
StartY(20, 1) = 1996 | |
StartY(21, 1) = 2001 | |
StartY(22, 1) = 2006 | |
StartY(23, 1) = 2011 | |
StartY(24, 1) = 2016 | |
StartY(25, 1) = 2021 | |
StartY(26, 1) = 2026 | |
StartY(27, 1) = 2031 | |
StartY(28, 1) = 2036 | |
StartY(29, 1) = 2041 | |
StartY(30, 1) = 2046 | |
StartY(31, 1) = 2051 | |
StartY(32, 1) = 2056 | |
StartY(33, 1) = 2061 | |
StartY(34, 1) = 2066 | |
StartY(35, 1) = 2071 | |
StartY(36, 1) = 2076 | |
StartY(37, 1) = 2081 | |
StartY(38, 1) = 2086 | |
StartY(39, 1) = 2091 | |
StartY(40, 1) = 2096 | |
StartY(41, 1) = 2101 | |
StartY(42, 1) = 2106 | |
StartY(43, 1) = 2111 | |
StartY(44, 1) = 2116 | |
StartY(45, 1) = 2121 | |
StartY(46, 1) = 2126 | |
StartY(47, 1) = 2131 | |
StartY(48, 1) = 2136 | |
StartY(49, 1) = 2141 | |
StartY(50, 1) = 2146 | |
StartY(51, 1) = 2151 | |
StartY(52, 1) = 2156 | |
StartY(53, 1) = 2161 | |
StartY(54, 1) = 2166 | |
StartY(55, 1) = 2171 | |
StartY(56, 1) = 2176 | |
StartY(57, 1) = 2181 | |
StartY(58, 1) = 2186 | |
StartY(59, 1) = 2191 | |
StartY(60, 1) = 2196 | |
StartY(61, 1) = 2201 | |
StartY(62, 1) = 2206 | |
StartY(63, 1) = 2211 | |
StartY(64, 1) = 2216 | |
StartY(65, 1) = 2221 | |
StartY(66, 1) = 2226 | |
StartY(67, 1) = 2231 | |
StartY(68, 1) = 2236 | |
StartY(69, 1) = 2241 | |
StartY(70, 1) = 2246 | |
StartY(71, 1) = 2251 | |
StartY(72, 1) = 2256 | |
StartY(73, 1) = 2261 | |
StartY(74, 1) = 2266 | |
StartY(75, 1) = 2271 | |
StartY(76, 1) = 2276 | |
StartY(77, 1) = 2281 | |
StartY(78, 1) = 2286 | |
StartY(79, 1) = 2291 | |
StartY(80, 1) = 2296 | |
StartY(81, 1) = 2301 | |
StartY(82, 1) = 2306 | |
StartY(83, 1) = 2311 | |
StartY(84, 1) = 2316 | |
StartY(85, 1) = 2321 | |
StartY(86, 1) = 2326 | |
StartY(87, 1) = 2331 | |
StartY(88, 1) = 2336 | |
StartY(89, 1) = 2341 | |
StartY(90, 1) = 2346 | |
StartY(91, 1) = 2351 | |
StartY(92, 1) = 2356 | |
StartY(93, 1) = 2361 | |
StartY(94, 1) = 2366 | |
StartY(95, 1) = 2371 | |
StartY(96, 1) = 2376 | |
StartY(97, 1) = 2381 | |
StartY(98, 1) = 2386 | |
StartY(99, 1) = 2391 | |
StartY(100, 1) = 2396 | |
StartY(101, 1) = 2401 | |
StartY(102, 1) = 2406 | |
StartY(103, 1) = 2411 | |
StartY(104, 1) = 2416 | |
StartY(105, 1) = 2421 | |
StartY(106, 1) = 2426 | |
StartY(107, 1) = 2431 | |
StartY(108, 1) = 2436 | |
StartY(109, 1) = 2441 | |
StartY(110, 1) = 2446 | |
StartY(111, 1) = 2451 | |
StartY(112, 1) = 2456 | |
StartY(1, 2) = 0.122733000004352 | |
StartY(2, 2) = 1.91890000045229E-02 | |
StartY(3, 2) = -8.43549999953059E-02 | |
StartY(4, 2) = -0.187898999995135 | |
StartY(5, 2) = -0.291442999994964 | |
StartY(6, 2) = 7.44250000052413E-02 | |
StartY(7, 2) = -2.91189999945876E-02 | |
StartY(8, 2) = -0.132662999994416 | |
StartY(9, 2) = -0.236206999994245 | |
StartY(10, 2) = -0.339750999994074 | |
StartY(11, 2) = -0.443294999993903 | |
StartY(12, 2) = -7.74269999936981E-02 | |
StartY(13, 2) = -0.180970999993527 | |
StartY(14, 2) = -0.284514999993356 | |
StartY(15, 2) = -0.388058999993185 | |
StartY(16, 2) = -0.491602999993014 | |
StartY(17, 2) = -0.595146999992842 | |
StartY(18, 2) = -0.698690999992671 | |
StartY(19, 2) = -0.332822999992466 | |
StartY(20, 2) = -0.436366999992295 | |
StartY(21, 2) = -0.539910999992124 | |
StartY(22, 2) = -0.643454999991953 | |
StartY(23, 2) = 0.253001000008218 | |
StartY(24, 2) = 0.149457000008389 | |
StartY(25, 2) = -0.484674999991406 | |
StartY(26, 2) = -0.588218999991235 | |
StartY(27, 2) = 0.308237000008937 | |
StartY(28, 2) = 0.204693000009108 | |
StartY(29, 2) = 0.101149000009279 | |
StartY(30, 2) = -2.39499999055015E-03 | |
StartY(31, 2) = -0.105938999990379 | |
StartY(32, 2) = 0.259929000009826 | |
StartY(33, 2) = 0.156385000009997 | |
StartY(34, 2) = 5.28410000101682E-02 | |
StartY(35, 2) = -5.07029999896607E-02 | |
StartY(36, 2) = -0.15424699998949 | |
StartY(37, 2) = -0.257790999989318 | |
StartY(38, 2) = 0.108077000010887 | |
StartY(39, 2) = 4.53300001105772E-03 | |
StartY(40, 2) = -9.90109999887712E-02 | |
StartY(41, 2) = -0.2025549999886 | |
StartY(42, 2) = -0.306098999988429 | |
StartY(43, 2) = -0.409642999988258 | |
StartY(44, 2) = -4.37749999880528E-02 | |
StartY(45, 2) = -0.147318999987882 | |
StartY(46, 2) = -0.250862999987711 | |
StartY(47, 2) = -0.354406999987539 | |
StartY(48, 2) = -0.457950999987368 | |
StartY(49, 2) = -0.561494999987197 | |
StartY(50, 2) = -0.665038999987026 | |
StartY(51, 2) = -0.299170999986821 | |
StartY(52, 2) = -0.40271499998665 | |
StartY(53, 2) = -0.506258999986479 | |
StartY(54, 2) = -0.609802999986308 | |
StartY(55, 2) = -0.713346999986137 | |
StartY(56, 2) = 0.183109000014035 | |
StartY(57, 2) = -0.45102299998576 | |
StartY(58, 2) = -0.554566999985589 | |
StartY(59, 2) = 0.341889000014582 | |
StartY(60, 2) = 0.238345000014753 | |
StartY(61, 2) = 0.134801000014924 | |
StartY(62, 2) = 3.12570000150951E-02 | |
StartY(63, 2) = -7.22869999847338E-02 | |
StartY(64, 2) = 0.293581000015471 | |
StartY(65, 2) = 0.190037000015642 | |
StartY(66, 2) = 8.64930000158135E-02 | |
StartY(67, 2) = -1.70509999840154E-02 | |
StartY(68, 2) = -0.120594999983844 | |
StartY(69, 2) = -0.224138999983673 | |
StartY(70, 2) = 0.141729000016532 | |
StartY(71, 2) = 0.038185000016703 | |
StartY(72, 2) = -6.53589999831259E-02 | |
StartY(73, 2) = -0.168902999982955 | |
StartY(74, 2) = -0.272446999982784 | |
StartY(75, 2) = -0.375990999982613 | |
StartY(76, 2) = -1.01229999824075E-02 | |
StartY(77, 2) = -0.113666999982236 | |
StartY(78, 2) = -0.217210999982065 | |
StartY(79, 2) = -0.320754999981894 | |
StartY(80, 2) = -0.424298999981723 | |
StartY(81, 2) = -0.527842999981552 | |
StartY(82, 2) = -0.631386999981381 | |
StartY(83, 2) = -0.265518999981176 | |
StartY(84, 2) = -0.369062999981005 | |
StartY(85, 2) = -0.472606999980834 | |
StartY(86, 2) = -0.576150999980662 | |
StartY(87, 2) = -0.679694999980491 | |
StartY(88, 2) = 0.21676100001968 | |
StartY(89, 2) = -0.417370999980115 | |
StartY(90, 2) = -0.520914999979944 | |
StartY(91, 2) = -0.624458999979773 | |
StartY(92, 2) = 0.271997000020398 | |
StartY(93, 2) = 0.168453000020569 | |
StartY(94, 2) = 6.49090000207404E-02 | |
StartY(95, 2) = -3.86349999790885E-02 | |
StartY(96, 2) = 0.327233000021117 | |
StartY(97, 2) = 0.223689000021288 | |
StartY(98, 2) = 0.120145000021459 | |
StartY(99, 2) = 1.66010000216299E-02 | |
StartY(100, 2) = -0.086942999978199 | |
StartY(101, 2) = -0.190486999978028 | |
StartY(102, 2) = 0.175381000022177 | |
StartY(103, 2) = 7.18370000223483E-02 | |
StartY(104, 2) = -3.17069999774806E-02 | |
StartY(105, 2) = -0.135250999977309 | |
StartY(106, 2) = -0.238794999977138 | |
StartY(107, 2) = -0.342338999976967 | |
StartY(108, 2) = 2.35290000232378E-02 | |
StartY(109, 2) = -8.00149999765911E-02 | |
StartY(110, 2) = -0.18355899997642 | |
StartY(111, 2) = -0.287102999976249 | |
StartY(112, 2) = -0.390646999976078 | |
Select Case iYear | |
Case Is >= 2456 | |
Fyear = StartY(112, 1) | |
FDev = StartY(112, 2) | |
Case Is >= 2451 | |
Fyear = StartY(111, 1) | |
FDev = StartY(111, 2) | |
Case Is >= 2446 | |
Fyear = StartY(110, 1) | |
FDev = StartY(110, 2) | |
Case Is >= 2441 | |
Fyear = StartY(109, 1) | |
FDev = StartY(109, 2) | |
Case Is >= 2436 | |
Fyear = StartY(108, 1) | |
FDev = StartY(108, 2) | |
Case Is >= 2431 | |
Fyear = StartY(107, 1) | |
FDev = StartY(107, 2) | |
Case Is >= 2426 | |
Fyear = StartY(106, 1) | |
FDev = StartY(106, 2) | |
Case Is >= 2421 | |
Fyear = StartY(105, 1) | |
FDev = StartY(105, 2) | |
Case Is >= 2416 | |
Fyear = StartY(104, 1) | |
FDev = StartY(104, 2) | |
Case Is >= 2411 | |
Fyear = StartY(103, 1) | |
FDev = StartY(103, 2) | |
Case Is >= 2406 | |
Fyear = StartY(102, 1) | |
FDev = StartY(102, 2) | |
Case Is >= 2401 | |
Fyear = StartY(101, 1) | |
FDev = StartY(101, 2) | |
Case Is >= 2396 | |
Fyear = StartY(100, 1) | |
FDev = StartY(100, 2) | |
Case Is >= 2391 | |
Fyear = StartY(99, 1) | |
FDev = StartY(99, 2) | |
Case Is >= 2386 | |
Fyear = StartY(98, 1) | |
FDev = StartY(98, 2) | |
Case Is >= 2381 | |
Fyear = StartY(97, 1) | |
FDev = StartY(97, 2) | |
Case Is >= 2376 | |
Fyear = StartY(96, 1) | |
FDev = StartY(96, 2) | |
Case Is >= 2371 | |
Fyear = StartY(95, 1) | |
FDev = StartY(95, 2) | |
Case Is >= 2366 | |
Fyear = StartY(94, 1) | |
FDev = StartY(94, 2) | |
Case Is >= 2361 | |
Fyear = StartY(93, 1) | |
FDev = StartY(93, 2) | |
Case Is >= 2356 | |
Fyear = StartY(92, 1) | |
FDev = StartY(92, 2) | |
Case Is >= 2351 | |
Fyear = StartY(91, 1) | |
FDev = StartY(91, 2) | |
Case Is >= 2346 | |
Fyear = StartY(90, 1) | |
FDev = StartY(90, 2) | |
Case Is >= 2341 | |
Fyear = StartY(89, 1) | |
FDev = StartY(89, 2) | |
Case Is >= 2336 | |
Fyear = StartY(88, 1) | |
FDev = StartY(88, 2) | |
Case Is >= 2331 | |
Fyear = StartY(87, 1) | |
FDev = StartY(87, 2) | |
Case Is >= 2326 | |
Fyear = StartY(86, 1) | |
FDev = StartY(86, 2) | |
Case Is >= 2321 | |
Fyear = StartY(85, 1) | |
FDev = StartY(85, 2) | |
Case Is >= 2316 | |
Fyear = StartY(84, 1) | |
FDev = StartY(84, 2) | |
Case Is >= 2311 | |
Fyear = StartY(83, 1) | |
FDev = StartY(83, 2) | |
Case Is >= 2306 | |
Fyear = StartY(82, 1) | |
FDev = StartY(82, 2) | |
Case Is >= 2301 | |
Fyear = StartY(81, 1) | |
FDev = StartY(81, 2) | |
Case Is >= 2296 | |
Fyear = StartY(80, 1) | |
FDev = StartY(80, 2) | |
Case Is >= 2291 | |
Fyear = StartY(79, 1) | |
FDev = StartY(79, 2) | |
Case Is >= 2286 | |
Fyear = StartY(78, 1) | |
FDev = StartY(78, 2) | |
Case Is >= 2281 | |
Fyear = StartY(77, 1) | |
FDev = StartY(77, 2) | |
Case Is >= 2276 | |
Fyear = StartY(76, 1) | |
FDev = StartY(76, 2) | |
Case Is >= 2271 | |
Fyear = StartY(75, 1) | |
FDev = StartY(75, 2) | |
Case Is >= 2266 | |
Fyear = StartY(74, 1) | |
FDev = StartY(74, 2) | |
Case Is >= 2261 | |
Fyear = StartY(73, 1) | |
FDev = StartY(73, 2) | |
Case Is >= 2256 | |
Fyear = StartY(72, 1) | |
FDev = StartY(72, 2) | |
Case Is >= 2251 | |
Fyear = StartY(71, 1) | |
FDev = StartY(71, 2) | |
Case Is >= 2246 | |
Fyear = StartY(70, 1) | |
FDev = StartY(70, 2) | |
Case Is >= 2241 | |
Fyear = StartY(69, 1) | |
FDev = StartY(69, 2) | |
Case Is >= 2236 | |
Fyear = StartY(68, 1) | |
FDev = StartY(68, 2) | |
Case Is >= 2231 | |
Fyear = StartY(67, 1) | |
FDev = StartY(67, 2) | |
Case Is >= 2226 | |
Fyear = StartY(66, 1) | |
FDev = StartY(66, 2) | |
Case Is >= 2221 | |
Fyear = StartY(65, 1) | |
FDev = StartY(65, 2) | |
Case Is >= 2216 | |
Fyear = StartY(64, 1) | |
FDev = StartY(64, 2) | |
Case Is >= 2211 | |
Fyear = StartY(63, 1) | |
FDev = StartY(63, 2) | |
Case Is >= 2206 | |
Fyear = StartY(62, 1) | |
FDev = StartY(62, 2) | |
Case Is >= 2201 | |
Fyear = StartY(61, 1) | |
FDev = StartY(61, 2) | |
Case Is >= 2196 | |
Fyear = StartY(60, 1) | |
FDev = StartY(60, 2) | |
Case Is >= 2191 | |
Fyear = StartY(59, 1) | |
FDev = StartY(59, 2) | |
Case Is >= 2186 | |
Fyear = StartY(58, 1) | |
FDev = StartY(58, 2) | |
Case Is >= 2181 | |
Fyear = StartY(57, 1) | |
FDev = StartY(57, 2) | |
Case Is >= 2176 | |
Fyear = StartY(56, 1) | |
FDev = StartY(56, 2) | |
Case Is >= 2171 | |
Fyear = StartY(55, 1) | |
FDev = StartY(55, 2) | |
Case Is >= 2166 | |
Fyear = StartY(54, 1) | |
FDev = StartY(54, 2) | |
Case Is >= 2161 | |
Fyear = StartY(53, 1) | |
FDev = StartY(53, 2) | |
Case Is >= 2156 | |
Fyear = StartY(52, 1) | |
FDev = StartY(52, 2) | |
Case Is >= 2151 | |
Fyear = StartY(51, 1) | |
FDev = StartY(51, 2) | |
Case Is >= 2146 | |
Fyear = StartY(50, 1) | |
FDev = StartY(50, 2) | |
Case Is >= 2141 | |
Fyear = StartY(49, 1) | |
FDev = StartY(49, 2) | |
Case Is >= 2136 | |
Fyear = StartY(48, 1) | |
FDev = StartY(48, 2) | |
Case Is >= 2131 | |
Fyear = StartY(47, 1) | |
FDev = StartY(47, 2) | |
Case Is >= 2126 | |
Fyear = StartY(46, 1) | |
FDev = StartY(46, 2) | |
Case Is >= 2121 | |
Fyear = StartY(45, 1) | |
FDev = StartY(45, 2) | |
Case Is >= 2116 | |
Fyear = StartY(44, 1) | |
FDev = StartY(44, 2) | |
Case Is >= 2111 | |
Fyear = StartY(43, 1) | |
FDev = StartY(43, 2) | |
Case Is >= 2106 | |
Fyear = StartY(42, 1) | |
FDev = StartY(42, 2) | |
Case Is >= 2101 | |
Fyear = StartY(41, 1) | |
FDev = StartY(41, 2) | |
Case Is >= 2096 | |
Fyear = StartY(40, 1) | |
FDev = StartY(40, 2) | |
Case Is >= 2091 | |
Fyear = StartY(39, 1) | |
FDev = StartY(39, 2) | |
Case Is >= 2086 | |
Fyear = StartY(38, 1) | |
FDev = StartY(38, 2) | |
Case Is >= 2081 | |
Fyear = StartY(37, 1) | |
FDev = StartY(37, 2) | |
Case Is >= 2076 | |
Fyear = StartY(36, 1) | |
FDev = StartY(36, 2) | |
Case Is >= 2071 | |
Fyear = StartY(35, 1) | |
FDev = StartY(35, 2) | |
Case Is >= 2066 | |
Fyear = StartY(34, 1) | |
FDev = StartY(34, 2) | |
Case Is >= 2061 | |
Fyear = StartY(33, 1) | |
FDev = StartY(33, 2) | |
Case Is >= 2056 | |
Fyear = StartY(32, 1) | |
FDev = StartY(32, 2) | |
Case Is >= 2051 | |
Fyear = StartY(31, 1) | |
FDev = StartY(31, 2) | |
Case Is >= 2046 | |
Fyear = StartY(30, 1) | |
FDev = StartY(30, 2) | |
Case Is >= 2041 | |
Fyear = StartY(29, 1) | |
FDev = StartY(29, 2) | |
Case Is >= 2036 | |
Fyear = StartY(28, 1) | |
FDev = StartY(28, 2) | |
Case Is >= 2031 | |
Fyear = StartY(27, 1) | |
FDev = StartY(27, 2) | |
Case Is >= 2026 | |
Fyear = StartY(26, 1) | |
FDev = StartY(26, 2) | |
Case Is >= 2021 | |
Fyear = StartY(25, 1) | |
FDev = StartY(25, 2) | |
Case Is >= 2016 | |
Fyear = StartY(24, 1) | |
FDev = StartY(24, 2) | |
Case Is >= 2011 | |
Fyear = StartY(23, 1) | |
FDev = StartY(23, 2) | |
Case Is >= 2006 | |
Fyear = StartY(22, 1) | |
FDev = StartY(22, 2) | |
Case Is >= 2001 | |
Fyear = StartY(21, 1) | |
FDev = StartY(21, 2) | |
Case Is >= 1996 | |
Fyear = StartY(20, 1) | |
FDev = StartY(20, 2) | |
Case Is >= 1991 | |
Fyear = StartY(19, 1) | |
FDev = StartY(19, 2) | |
Case Is >= 1986 | |
Fyear = StartY(18, 1) | |
FDev = StartY(18, 2) | |
Case Is >= 1981 | |
Fyear = StartY(17, 1) | |
FDev = StartY(17, 2) | |
Case Is >= 1976 | |
Fyear = StartY(16, 1) | |
FDev = StartY(16, 2) | |
Case Is >= 1971 | |
Fyear = StartY(15, 1) | |
FDev = StartY(15, 2) | |
Case Is >= 1966 | |
Fyear = StartY(14, 1) | |
FDev = StartY(14, 2) | |
Case Is >= 1961 | |
Fyear = StartY(13, 1) | |
FDev = StartY(13, 2) | |
Case Is >= 1956 | |
Fyear = StartY(12, 1) | |
FDev = StartY(12, 2) | |
Case Is >= 1951 | |
Fyear = StartY(11, 1) | |
FDev = StartY(11, 2) | |
Case Is >= 1946 | |
Fyear = StartY(10, 1) | |
FDev = StartY(10, 2) | |
Case Is >= 1941 | |
Fyear = StartY(9, 1) | |
FDev = StartY(9, 2) | |
Case Is >= 1936 | |
Fyear = StartY(8, 1) | |
FDev = StartY(8, 2) | |
Case Is >= 1931 | |
Fyear = StartY(7, 1) | |
FDev = StartY(7, 2) | |
Case Is >= 1926 | |
Fyear = StartY(6, 1) | |
FDev = StartY(6, 2) | |
Case Is >= 1921 | |
Fyear = StartY(5, 1) | |
FDev = StartY(5, 2) | |
Case Is >= 1916 | |
Fyear = StartY(4, 1) | |
FDev = StartY(4, 2) | |
Case Is >= 1911 | |
Fyear = StartY(3, 1) | |
FDev = StartY(3, 2) | |
Case Is >= 1906 | |
Fyear = StartY(2, 1) | |
FDev = StartY(2, 2) | |
Case Is >= 1901 | |
Fyear = StartY(1, 1) | |
FDev = StartY(1, 2) | |
Case Else | |
Deviation = 0 | |
Exit Function | |
End Select | |
'Debug.Print "Select = " & Fyear & " FDev: " & FDev | |
If iYear = Fyear Then | |
CurrDev = FDev | |
Else | |
Fyear = Fyear + 1 | |
For i = Fyear To iYear | |
'ถ้า i = ปีเริ่มต้น ให้ใช้ข้อมูลการเบี่ยงเบนของปีเริ่มต้นมาแสดงผล | |
If i = Fyear Then | |
lastDev = FDev | |
Else | |
lastDev = CurrDev | |
End If | |
'ถ้าปีก่อนหน้าเป็นอธิกมาส | |
If AthikaMas(i - 1) = True Then | |
CurrDev = -0.102356 | |
'ถ้าปีก่อนหน้าเป็นอธิกวาร | |
ElseIf AthikaVar(i - 1) = True Then | |
CurrDev = -0.632944 | |
'ถ้าปีก่อนหน้าเป็นปีปกติ | |
Else | |
CurrDev = 0.367056 | |
End If | |
CurrDev = lastDev + CurrDev | |
'Debug.Print "First: " & Fyear & " input: " & iYear & " Loop: " & i & " CurrentDev: " & CurrDev | |
Next i | |
End If | |
Deviation = CurrDev | |
End Function | |
Public Function LDayInYear(iYear As Integer) | |
'calculation for number in year of lunarday | |
'return value of lunar days in year for Thai Lunar Date | |
If AthikaMas(iYear) = True Then | |
LDayInYear = 384 | |
ElseIf AthikaVar(iYear) = True Then | |
LDayInYear = 355 | |
Else | |
LDayInYear = 354 | |
End If | |
End Function | |
Public Function AthikaSurathin(iYear As Integer) As Boolean | |
'Calculation for leap year | |
'return value true if it is a leap year. | |
Dim Tmp As Boolean | |
If iYear Mod 400 = 0 Then | |
Tmp = True | |
ElseIf iYear Mod 100 = 0 Then | |
Tmp = False | |
ElseIf iYear Mod 4 = 0 Then | |
Tmp = True | |
Else | |
Tmp = False | |
End If | |
AthikaSurathin = Tmp | |
End Function | |
Public Function NODIYear(iYear As Integer) As Integer | |
'NODIYEAR = Number of day in the year | |
'Amount Number of days in specified year | |
'Copyright 2022 and later by Pongsathorn Sraouthai | |
If AthikaSurathin(iYear) = True Then | |
NODIYear = 366 | |
Else | |
NODIYear = 365 | |
End If | |
End Function | |
Public Function ThZodiac(iYear As Integer, Optional oType As Integer = 1) | |
'ThZodiac = Thai Zodiac Year Name | |
'Return Zodiac Name of specified Year | |
'Copyright 2022 and later by Pongsathorn Sraouthai | |
' | |
'oType = Output Type | |
'1 = Thai | |
'2 = English | |
'3 = Number | |
'4 = Picture | |
'5 = Sok | |
Dim Zodiac(1 To 4, 1 To 12) | |
Dim result | |
Zodiac(1, 1) = "ชวด" | |
Zodiac(1, 2) = "ฉลู" | |
Zodiac(1, 3) = "ขาล" | |
Zodiac(1, 4) = "เถาะ" | |
Zodiac(1, 5) = "มะโรง" | |
Zodiac(1, 6) = "มะเส็ง" | |
Zodiac(1, 7) = "มะเมีย" | |
Zodiac(1, 8) = "มะแม" | |
Zodiac(1, 9) = "วอก" | |
Zodiac(1, 10) = "ระกา" | |
Zodiac(1, 11) = "จอ" | |
Zodiac(1, 12) = "กุน" | |
Zodiac(2, 1) = "RAT" | |
Zodiac(2, 2) = "OX" | |
Zodiac(2, 3) = "TIGER" | |
Zodiac(2, 4) = "RABBIT" | |
Zodiac(2, 5) = "DRAGON" | |
Zodiac(2, 6) = "SNAKE" | |
Zodiac(2, 7) = "HORSE" | |
Zodiac(2, 8) = "GOAT" | |
Zodiac(2, 9) = "MONKEY" | |
Zodiac(2, 10) = "ROOSTER" | |
Zodiac(2, 11) = "DOG" | |
Zodiac(2, 12) = "PIG" | |
Zodiac(3, 1) = 1 | |
Zodiac(3, 2) = 2 | |
Zodiac(3, 3) = 3 | |
Zodiac(3, 4) = 4 | |
Zodiac(3, 5) = 5 | |
Zodiac(3, 6) = 6 | |
Zodiac(3, 7) = 7 | |
Zodiac(3, 8) = 8 | |
Zodiac(3, 9) = 9 | |
Zodiac(3, 10) = 10 | |
Zodiac(3, 11) = 11 | |
Zodiac(3, 12) = 12 | |
Zodiac(4, 1) = U2W("-10179 -9171") | |
Zodiac(4, 2) = U2W("-10179 -9170") | |
Zodiac(4, 3) = U2W("-10179 -9169") | |
Zodiac(4, 4) = U2W("-10179 -9168") | |
Zodiac(4, 5) = U2W("-10179 -9166") | |
Zodiac(4, 6) = U2W("-10179 -9203") | |
Zodiac(4, 7) = U2W("-10179 -9164") | |
Zodiac(4, 8) = U2W("-10179 -9200") | |
Zodiac(4, 9) = U2W("-10179 -9163") | |
Zodiac(4, 10) = U2W("-10179 -9196") | |
Zodiac(4, 11) = U2W("-10179 -9162") | |
Zodiac(4, 12) = U2W("-10179 -9161") | |
result = iYear Mod 12 | |
If result - 3 < 1 Then | |
result = result - 3 + 12 | |
Else | |
result = result - 3 | |
End If | |
If oType = 5 Then | |
ThZodiac = Zodiac(1, result) & ThSok(iYear) | |
Else | |
ThZodiac = Zodiac(oType, result) | |
End If | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment