Last active
February 18, 2024 09:19
-
-
Save touchiep/ec68878bde8f390594bc00b175940880 to your computer and use it in GitHub Desktop.
[VBA][OpenOffice][LibraOffice] สูตรสำหรับแปลงวันที่ปกติ ให้เป็นจันทรคติไทย สำหรับใช้กับ OpenOffice หรือ LibreOffice
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
Option Explicit | |
Private Function XLMod(a, b) | |
' This attempts to mimic the Excel MOD function | |
XLMod = a - b * Int(a / b) | |
End Function | |
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 | |
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 | |
Dim StartY(1 To 56, 1 To 2) | |
StartY(1, 1) = 1901 | |
StartY(2, 1) = 1911 | |
StartY(3, 1) = 1921 | |
StartY(4, 1) = 1931 | |
StartY(5, 1) = 1941 | |
StartY(6, 1) = 1951 | |
StartY(7, 1) = 1961 | |
StartY(8, 1) = 1971 | |
StartY(9, 1) = 1981 | |
StartY(10, 1) = 1991 | |
StartY(11, 1) = 2001 | |
StartY(12, 1) = 2011 | |
StartY(13, 1) = 2021 | |
StartY(14, 1) = 2031 | |
StartY(15, 1) = 2041 | |
StartY(16, 1) = 2051 | |
StartY(17, 1) = 2061 | |
StartY(18, 1) = 2071 | |
StartY(19, 1) = 2081 | |
StartY(20, 1) = 2091 | |
StartY(21, 1) = 2101 | |
StartY(22, 1) = 2111 | |
StartY(23, 1) = 2121 | |
StartY(24, 1) = 2131 | |
StartY(25, 1) = 2141 | |
StartY(26, 1) = 2151 | |
StartY(27, 1) = 2161 | |
StartY(28, 1) = 2171 | |
StartY(29, 1) = 2181 | |
StartY(30, 1) = 2191 | |
StartY(31, 1) = 2201 | |
StartY(32, 1) = 2211 | |
StartY(33, 1) = 2221 | |
StartY(34, 1) = 2231 | |
StartY(35, 1) = 2241 | |
StartY(36, 1) = 2251 | |
StartY(37, 1) = 2261 | |
StartY(38, 1) = 2271 | |
StartY(39, 1) = 2281 | |
StartY(40, 1) = 2291 | |
StartY(41, 1) = 2301 | |
StartY(42, 1) = 2311 | |
StartY(43, 1) = 2321 | |
StartY(44, 1) = 2331 | |
StartY(45, 1) = 2341 | |
StartY(46, 1) = 2351 | |
StartY(47, 1) = 2361 | |
StartY(48, 1) = 2371 | |
StartY(49, 1) = 2381 | |
StartY(50, 1) = 2391 | |
StartY(51, 1) = 2401 | |
StartY(52, 1) = 2411 | |
StartY(53, 1) = 2421 | |
StartY(54, 1) = 2431 | |
StartY(55, 1) = 2441 | |
StartY(56, 1) = 2451 | |
StartY(1, 2) = 0.122733000004352 | |
StartY(2, 2) = -8.43549999953059E-02 | |
StartY(3, 2) = -0.291442999994964 | |
StartY(4, 2) = -2.91189999945876E-02 | |
StartY(5, 2) = -0.236206999994245 | |
StartY(6, 2) = -0.443294999993903 | |
StartY(7, 2) = -0.180970999993527 | |
StartY(8, 2) = -0.388058999993185 | |
StartY(9, 2) = -0.595146999992842 | |
StartY(10, 2) = -0.332822999992466 | |
StartY(11, 2) = -0.539910999992124 | |
StartY(12, 2) = 0.253001000008218 | |
StartY(13, 2) = -0.484674999991406 | |
StartY(14, 2) = 0.308237000008937 | |
StartY(15, 2) = 0.101149000009279 | |
StartY(16, 2) = -0.105938999990379 | |
StartY(17, 2) = 0.156385000009997 | |
StartY(18, 2) = -5.07029999896607E-02 | |
StartY(19, 2) = -0.257790999989318 | |
StartY(20, 2) = 4.53300001105772E-03 | |
StartY(21, 2) = -0.2025549999886 | |
StartY(22, 2) = -0.409642999988258 | |
StartY(23, 2) = -0.147318999987882 | |
StartY(24, 2) = -0.354406999987539 | |
StartY(25, 2) = -0.561494999987197 | |
StartY(26, 2) = -0.299170999986821 | |
StartY(27, 2) = -0.506258999986479 | |
StartY(28, 2) = -0.713346999986137 | |
StartY(29, 2) = -0.45102299998576 | |
StartY(30, 2) = 0.341889000014582 | |
StartY(31, 2) = 0.134801000014924 | |
StartY(32, 2) = -7.22869999847338E-02 | |
StartY(33, 2) = 0.190037000015642 | |
StartY(34, 2) = -1.70509999840154E-02 | |
StartY(35, 2) = -0.224138999983673 | |
StartY(36, 2) = 0.038185000016703 | |
StartY(37, 2) = -0.168902999982955 | |
StartY(38, 2) = -0.375990999982613 | |
StartY(39, 2) = -0.113666999982236 | |
StartY(40, 2) = -0.320754999981894 | |
StartY(41, 2) = -0.527842999981552 | |
StartY(42, 2) = -0.265518999981176 | |
StartY(43, 2) = -0.472606999980834 | |
StartY(44, 2) = -0.679694999980491 | |
StartY(45, 2) = -0.417370999980115 | |
StartY(46, 2) = -0.624458999979773 | |
StartY(47, 2) = 0.168453000020569 | |
StartY(48, 2) = -3.86349999790885E-02 | |
StartY(49, 2) = 0.223689000021288 | |
StartY(50, 2) = 1.66010000216299E-02 | |
StartY(51, 2) = -0.190486999978028 | |
StartY(52, 2) = 7.18370000223483E-02 | |
StartY(53, 2) = -0.135250999977309 | |
StartY(54, 2) = -0.342338999976967 | |
StartY(55, 2) = -8.00149999765911E-02 | |
StartY(56, 2) = -0.287102999976249 | |
Select Case iYear | |
Case Is < 1911 | |
Fyear = StartY(1, 1) | |
FDev = StartY(1, 2) | |
Case Is < 1921 | |
Fyear = StartY(2, 1) | |
FDev = StartY(2, 2) | |
Case Is < 1931 | |
Fyear = StartY(3, 1) | |
FDev = StartY(3, 2) | |
Case Is < 1941 | |
Fyear = StartY(4, 1) | |
FDev = StartY(4, 2) | |
Case Is < 1951 | |
Fyear = StartY(5, 1) | |
FDev = StartY(5, 2) | |
Case Is < 1961 | |
Fyear = StartY(6, 1) | |
FDev = StartY(6, 2) | |
Case Is < 1971 | |
Fyear = StartY(7, 1) | |
FDev = StartY(7, 2) | |
Case Is < 1981 | |
Fyear = StartY(8, 1) | |
FDev = StartY(8, 2) | |
Case Is < 1991 | |
Fyear = StartY(9, 1) | |
FDev = StartY(9, 2) | |
Case Is < 2001 | |
Fyear = StartY(10, 1) | |
FDev = StartY(10, 2) | |
Case Is < 2011 | |
Fyear = StartY(11, 1) | |
FDev = StartY(11, 2) | |
Case Is < 2021 | |
Fyear = StartY(12, 1) | |
FDev = StartY(12, 2) | |
Case Is < 2031 | |
Fyear = StartY(13, 1) | |
FDev = StartY(13, 2) | |
Case Is < 2041 | |
Fyear = StartY(14, 1) | |
FDev = StartY(14, 2) | |
Case Is < 2051 | |
Fyear = StartY(15, 1) | |
FDev = StartY(15, 2) | |
Case Is < 2061 | |
Fyear = StartY(16, 1) | |
FDev = StartY(16, 2) | |
Case Is < 2071 | |
Fyear = StartY(17, 1) | |
FDev = StartY(17, 2) | |
Case Is < 2081 | |
Fyear = StartY(18, 1) | |
FDev = StartY(18, 2) | |
Case Is < 2091 | |
Fyear = StartY(19, 1) | |
FDev = StartY(19, 2) | |
Case Is < 2101 | |
Fyear = StartY(20, 1) | |
FDev = StartY(20, 2) | |
Case Is < 2111 | |
Fyear = StartY(21, 1) | |
FDev = StartY(21, 2) | |
Case Is < 2121 | |
Fyear = StartY(22, 1) | |
FDev = StartY(22, 2) | |
Case Is < 2131 | |
Fyear = StartY(23, 1) | |
FDev = StartY(23, 2) | |
Case Is < 2141 | |
Fyear = StartY(24, 1) | |
FDev = StartY(24, 2) | |
Case Is < 2151 | |
Fyear = StartY(25, 1) | |
FDev = StartY(25, 2) | |
Case Is < 2161 | |
Fyear = StartY(26, 1) | |
FDev = StartY(26, 2) | |
Case Is < 2171 | |
Fyear = StartY(27, 1) | |
FDev = StartY(27, 2) | |
Case Is < 2181 | |
Fyear = StartY(28, 1) | |
FDev = StartY(28, 2) | |
Case Is < 2191 | |
Fyear = StartY(29, 1) | |
FDev = StartY(29, 2) | |
Case Is < 2201 | |
Fyear = StartY(30, 1) | |
FDev = StartY(30, 2) | |
Case Is < 2211 | |
Fyear = StartY(31, 1) | |
FDev = StartY(31, 2) | |
Case Is < 2221 | |
Fyear = StartY(32, 1) | |
FDev = StartY(32, 2) | |
Case Is < 2231 | |
Fyear = StartY(33, 1) | |
FDev = StartY(33, 2) | |
Case Is < 2241 | |
Fyear = StartY(34, 1) | |
FDev = StartY(34, 2) | |
Case Is < 2251 | |
Fyear = StartY(35, 1) | |
FDev = StartY(35, 2) | |
Case Is < 2261 | |
Fyear = StartY(36, 1) | |
FDev = StartY(36, 2) | |
Case Is < 2271 | |
Fyear = StartY(37, 1) | |
FDev = StartY(37, 2) | |
Case Is < 2281 | |
Fyear = StartY(38, 1) | |
FDev = StartY(38, 2) | |
Case Is < 2291 | |
Fyear = StartY(39, 1) | |
FDev = StartY(39, 2) | |
Case Is < 2301 | |
Fyear = StartY(40, 1) | |
FDev = StartY(40, 2) | |
Case Is < 2311 | |
Fyear = StartY(41, 1) | |
FDev = StartY(41, 2) | |
Case Is < 2321 | |
Fyear = StartY(42, 1) | |
FDev = StartY(42, 2) | |
Case Is < 2331 | |
Fyear = StartY(43, 1) | |
FDev = StartY(43, 2) | |
Case Is < 2341 | |
Fyear = StartY(44, 1) | |
FDev = StartY(44, 2) | |
Case Is < 2351 | |
Fyear = StartY(45, 1) | |
FDev = StartY(45, 2) | |
Case Is < 2361 | |
Fyear = StartY(46, 1) | |
FDev = StartY(46, 2) | |
Case Is < 2371 | |
Fyear = StartY(47, 1) | |
FDev = StartY(47, 2) | |
Case Is < 2381 | |
Fyear = StartY(48, 1) | |
FDev = StartY(48, 2) | |
Case Is < 2391 | |
Fyear = StartY(49, 1) | |
FDev = StartY(49, 2) | |
Case Is < 2401 | |
Fyear = StartY(50, 1) | |
FDev = StartY(50, 2) | |
Case Is < 2411 | |
Fyear = StartY(51, 1) | |
FDev = StartY(51, 2) | |
Case Is < 2421 | |
Fyear = StartY(52, 1) | |
FDev = StartY(52, 2) | |
Case Is < 2431 | |
Fyear = StartY(53, 1) | |
FDev = StartY(53, 2) | |
Case Is < 2441 | |
Fyear = StartY(54, 1) | |
FDev = StartY(54, 2) | |
Case Is < 2451 | |
Fyear = StartY(55, 1) | |
FDev = StartY(55, 2) | |
Case Is < 2461 | |
Fyear = StartY(56, 1) | |
FDev = StartY(56, 2) | |
Case Else | |
Deviation = 0 | |
Exit Function | |
End Select | |
If iYear = Fyear Then | |
CurrDev = FDev | |
Else | |
For i = Fyear + 1 To iYear | |
If i = Fyear + 1 Then | |
lastDev = FDev | |
Else | |
lastDev = CurrDev | |
End If | |
If AthikaMas(i - 1) = True Then | |
CurrDev = -0.102356 | |
Else | |
If AthikaVar(i - 1) = True Then | |
CurrDev = -0.632944 | |
Else | |
CurrDev = 0.367056 | |
End If | |
End If | |
CurrDev = lastDev + CurrDev | |
Next i | |
End If | |
Deviation = CurrDev | |
End Function | |
Private 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 | |
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 | |
Private 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 | |
Function THLDate(iDate As Date, Optional ThaiNumber As Boolean, Optional ThaiZodiac As Boolean, Optional Era As Integer, Optional ZOption As Boolean, Optional Holiday As Boolean) | |
'THLDate = Thai Lunar Date สำหรับแสดงผลวันที่แบบจันทรคติไทย | |
'แปลงวันที่แบบสุริยคติให้เป็นจันทรคติ | |
'Copyright 2022 and later by Pongsathorn Sraouthai | |
' | |
'ตัวแปร | |
'iDate = วันที่ ที่ใช้อ้างอิง | |
'ThaiNumber = ถ้าเป็น True แสดงผลเลขไทยแทนเลขอารบิก | |
'ThaiZodiac = ถ้าเป็น True แสดงชื่อปีนักษัตร | |
'Era = แสดงศักราช 0=ไม่แสดง 1=พุทธศักราช 2=จุลศักราช 3=มหาศักราช 4=รัตนโกสินทร์ศก 5=คริสตศักราช | |
'Zoption = ตัวเลือกสำหรับการแสดงชื่อปีนักษัตร: False = ใช้รูปแบบราชการ, True = ใช้รูปแบบโหราศาสตร์ไทย | |
'Holiday = ถ้าเป็น 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 | |
'ตรวจสอบพารามิเตอร์ | |
if ismissing(ThaiNumber) = true then | |
ThaiNumber = False | |
end if | |
if ismissing(ThaiZodiac) = true then | |
ThaiZodiac = False | |
end if | |
if ismissing(Era) = True then | |
Era = 0 | |
end if | |
if ismissing(ZOption) = True Then | |
ZOption = False | |
end if | |
if ismissing(Holiday) = True then | |
Holiday = False | |
end if | |
'ตรวจสอบว่าเป็นปีที่รองรับการคำนวณได้หรือไม่ | |
If Year(iDate) < 1903 Or Year(iDate) > 2460 Then | |
THLDate = "ไม่รองรับ" | |
Exit Function | |
End If | |
'วารเริ่มต้นของการนับวาร วันขึ้น ๑ ค่ำ เดือน ๑ คือ ๓๐ พฤศจิกายน ๒๔๔๕ | |
BeginDate = DateSerial(1902, 11, 30) | |
'นับวารถึงปีก่อนหน้าปีปัจจุบัน | |
For i = 1903 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 14 | |
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 Else | |
End Select | |
Next | |
'ช่วงขึ้นปีใหม่ของราชการ | |
If ThM > 12 Then | |
ThM = ThM - 12 | |
ThZ = 1 | |
Else | |
ThZ = 0 | |
End If | |
If DofY > 15 Then | |
ThS = "แรม " | |
DofY = DofY - 15 | |
Else | |
ThS = "ขึ้น " | |
End If | |
THLDate = ThS & DofY & " ค่ำ เดือน " & ThM | |
Case 355 'ปีอธิกวาร | |
RDayLY = RDayPrev + NODIYear(Year(iDate)) | |
DofY = DayFromOne | |
For j = 1 To 14 | |
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 <= 30 And DofY > 0 Then Exit For Else DofY = DofY - 30 | |
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 Else | |
End Select | |
Next | |
If ThM > 12 Then | |
ThM = ThM - 12 | |
ThZ = 1 | |
Else | |
ThZ = 0 | |
End If | |
If DofY > 15 Then | |
ThS = "แรม " | |
DofY = DofY - 15 | |
Else | |
ThS = "ขึ้น " | |
End If | |
THLDate = ThS & DofY & " ค่ำ เดือน " & ThM | |
Case 384 'ปีอธิกมาส | |
RDayLY = RDayPrev + NODIYear(Year(iDate)) | |
DofY = DayFromOne | |
For j = 1 To 15 | |
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 Else | |
End Select | |
Next | |
If ThM > 13 Then | |
ThM = ThM - 13 | |
ThZ = 1 | |
Else | |
ThZ = 0 | |
End If | |
Select Case ThM | |
Case 9 | |
ThM = 88 | |
Case 10 | |
ThM = 9 | |
Case 11 | |
ThM = 10 | |
Case 12 | |
ThM = 11 | |
Case 13 | |
ThM = 12 | |
End Select | |
If DofY > 15 Then | |
ThS = "แรม " | |
DofY = DofY - 15 | |
Else | |
ThS = "ขึ้น " | |
End If | |
THLDate = ThS & DofY & " ค่ำ เดือน " & ThM | |
End Select | |
'เปิดใช้เลขไทย ถ้าตัวเลือก ThaiNumber เป็น True | |
If ThaiNumber = True Then THLDate = W2TH(CStr(THLDate)) | |
'แสดงปีนักษัตร ตามระบบราชการ ถ้าตัวเลือก ThaiZodiac เป็น True | |
If ThaiZodiac = True Then | |
If ZOption = False Then | |
If ThZ = 1 Then | |
THLDate = THLDate & " ปี" & ThZodiac(Year(iDate) + 1) | |
Else | |
THLDate = THLDate & " ปี" & ThZodiac(Year(iDate)) | |
End If | |
Else | |
ThH = ThM | |
If ThH < 5 And ThZ = 0 Then | |
THLDate = THLDate & " ปี" & ThZodiac(Year(iDate) - 1) | |
ElseIf ThH < 5 And ThZ = 1 Then | |
THLDate = THLDate & " ปี" & ThZodiac(Year(iDate)) | |
Else | |
THLDate = THLDate & " ปี" & ThZodiac(Year(iDate)) | |
End If | |
End If | |
End If | |
'แสดงปีศักราช ถ้าตัวเลือก Era เป็น 1-5 | |
Select Case Era | |
Case 1 | |
Select Case ThaiNumber | |
Case True | |
THLDate = W2TH(THLDate & " พุทธศักราช " & Year(iDate) + 543) | |
Case False | |
THLDate = THLDate & " พุทธศักราช " & Year(iDate) + 543 | |
End Select | |
Case 2 | |
Select Case ThaiNumber | |
Case True | |
THLDate = W2TH(THLDate & " จุลศักราช " & Year(iDate) - 638) | |
Case False | |
THLDate = THLDate & " จุลศักราช " & Year(iDate) - 638 | |
End Select | |
Case 3 | |
Select Case ThaiNumber | |
Case True | |
THLDate = W2TH(THLDate & " มหาศักราช " & Year(iDate) - 78) | |
Case False | |
THLDate = THLDate & " มหาศักราช " & Year(iDate) - 78 | |
End Select | |
Case 4 | |
Select Case ThaiNumber | |
Case True | |
THLDate = W2TH(THLDate & " รัตนโกสินทร์ศก " & Year(iDate) - 1781) | |
Case False | |
THLDate = THLDate & " รัตนโกสินทร์ศก " & Year(iDate) - 1781 | |
End Select | |
Case 5 | |
Select Case ThaiNumber | |
Case True | |
THLDate = W2TH(THLDate & " คริสตศักราช " & Year(iDate)) | |
Case False | |
THLDate = THLDate & " คริสตศักราช " & Year(iDate) | |
End Select | |
Case Else | |
End Select | |
If Holiday = True Then | |
THLDate = THLDate & " " & ThLunarHoliday(iDate) | |
End If | |
THLDate = Trim(THLDate) | |
End Function | |
Function ThZodiac(iYear As Integer, Optional oType As Integer) | |
'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 | |
Dim Zodiac(1 To 3, 1 To 12) | |
Dim Result | |
if ismissing(oType) = True then | |
oType = 1 | |
end if | |
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 | |
Result = iYear Mod 12 | |
If Result - 3 < 1 Then | |
Result = Result - 3 + 12 | |
Else | |
Result = Result - 3 | |
End If | |
ThZodiac = Zodiac(oType, Result) | |
End Function | |
Function ThLunarHoliday(iDate As Date) As String | |
'สำหรับแสดงผลวันสำคัญทางจันทรคติ | |
' | |
'จำเป็นต้องใช้ฟังชั่น Athikamas และ THLDate | |
' | |
If AthikaMas(Year(iDate)) = False Then | |
Select Case THLDate(iDate) | |
Case "ขึ้น 15 ค่ำ เดือน 3" | |
ThLunarHoliday = "วันมาฆบูชา" | |
Case "ขึ้น 15 ค่ำ เดือน 6" | |
ThLunarHoliday = "วันวิสาขบูชา" | |
Case "แรม 8 ค่ำ เดือน 6" | |
ThLunarHoliday = "วันอัฏฐมีบูชา" | |
Case "ขึ้น 15 ค่ำ เดือน 8" | |
ThLunarHoliday = "วันอาสาฬหบูชา" | |
Case "แรม 1 ค่ำ เดือน 8" | |
ThLunarHoliday = "วันเข้าพรรษา" | |
Case "ขึ้น 15 ค่ำ เดือน 11" | |
ThLunarHoliday = "วันออกพรรษา" | |
Case "ขึ้น 15 ค่ำ เดือน 12" | |
ThLunarHoliday = "วันลอยกระทง" | |
Case Else | |
ThLunarHoliday = "" | |
End Select | |
Else | |
Select Case THLDate(iDate) | |
Case "ขึ้น 15 ค่ำ เดือน 4" | |
ThLunarHoliday = "วันมาฆบูชา" | |
Case "ขึ้น 15 ค่ำ เดือน 7" | |
ThLunarHoliday = "วันวิสาขบูชา" | |
Case "แรม 8 ค่ำ เดือน 7" | |
ThLunarHoliday = "วันอัฏฐมีบูชา" | |
Case "ขึ้น 15 ค่ำ เดือน 88" | |
ThLunarHoliday = "วันอาสาฬหบูชา" | |
Case "แรม 1 ค่ำ เดือน 88" | |
ThLunarHoliday = "วันเข้าพรรษา" | |
Case "ขึ้น 15 ค่ำ เดือน 11" | |
ThLunarHoliday = "วันออกพรรษา" | |
Case "ขึ้น 15 ค่ำ เดือน 12" | |
ThLunarHoliday = "วันลอยกระทง" | |
Case Else | |
ThLunarHoliday = "" | |
End Select | |
End If | |
End Function | |
Function W2TH(strInput As String) As String | |
'สูตรสำหรับแปลงเลขอารบิกเป็นเลขไทย | |
Dim numberArray | |
numberArray = Array("0", "๐", _ | |
"1", "๑", _ | |
"2", "๒", _ | |
"3", "๓", _ | |
"4", "๔", _ | |
"5", "๕", _ | |
"6", "๖", _ | |
"7", "๗", _ | |
"8", "๘", _ | |
"9", "๙") | |
Dim i As Long | |
W2TH = strInput | |
For i = 0 To 18 Step 2 | |
W2TH = Replace(W2TH, numberArray(i), numberArray(i + 1)) | |
Next i | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment