Attribute VB_Name = "Module2" Function calulate_date_next(chktype As String, num_cal As Integer, r_date As Date) As Date Dim l As Integer Dim dd As Integer Dim mm As Integer Dim yy As Integer Dim sdd As String Dim smm As String Dim syy As String dd = Day(r_date) mm = Month(r_date) yy = Year(r_date) 'get exact day in month If mm = 1 Or mm = 3 Or mm = 5 Or mm = 7 Or mm = 8 Or mm = 10 Or mm = 12 Then l = 31 ElseIf mm = 4 Or mm = 6 Or mm = 9 Or mm = 11 Then l = 30 ElseIf mm = 2 Then If (yy Mod 4 = 0 And yy Mod 100 <> 0) Or yy Mod 400 = 0 Then l = 29 Else l = 28 End If End If Select Case chktype Case "D" dd = dd + num_cal If dd > l Then dd = dd - l mm = mm + 1 End If If mm > 12 Then mm = mm - 12 yy = yy + 1 End If Case "W" If dd = 15 Then dd = 1 mm = mm + 1 Else dd = 15 End If If mm > 12 Then mm = mm - 12 yy = yy + 1 End If Case "M" dd = 1 mm = mm + num_cal If mm > 12 Then mm = mm - 12 yy = yy + 1 End If Case "Y" dd = 1 mm = 1 yy = yy + 1 End Select sdd = LTrim(Str(dd)) smm = LTrim(Str(mm)) syy = LTrim(Str(yy)) l = Len(sdd) If l = 1 Then sdd = "0" + sdd l = Len(smm) If l = 1 Then smm = "0" + smm calulate_date_next = DateSerial(syy, smm, sdd) End Function Function calulate_date_bef(chktype As String, num_cal As Integer, r_date As Date) As Date Dim l As Integer Dim dd As Integer Dim mm As Integer Dim yy As Integer Dim sdd As String Dim smm As String Dim syy As String dd = Day(r_date) mm = Month(r_date) yy = Year(r_date) 'get exact day in month Select Case mm - 1 Case 1, 3, 5, 7, 8, 10, 0 l = 31 Case 4, 6, 9, 11 l = 30 Case 2 If (yy Mod 4 = 0 And yy Mod 100 <> 0) Or (yy Mod 400) = 0 Then l = 29 Else l = 28 End If End Select Select Case chktype Case "D" If dd > num_cal Then dd = dd - num_cal Else dd = dd + l - num_cal mm = mm - 1 End If If mm = 0 Then mm = 12 yy = yy - 1 End If Case "W" If dd > 15 Then dd = 15 ElseIf dd > 1 Then dd = 1 Else dd = 15 mm = mm - 1 End If If mm = 0 Then mm = 12 yy = yy - 1 End If Case "M" dd = 1 If mm > num_cal Then mm = mm - num_cal Else mm = mm + 12 - num_cal yy = yy - 1 End If Case "Y" dd = 1 mm = 1 yy = yy - 1 End Select sdd = LTrim(Str(dd)) smm = LTrim(Str(mm)) syy = LTrim(Str(yy)) l = Len(sdd) If l = 1 Then sdd = "0" + sdd l = Len(smm) If l = 1 Then smm = "0" + smm calulate_date_bef = DateSerial(syy, smm, sdd) End Function Function convert_date(d_date As Date) As String Dim mm As Integer Dim mm_con As String mm = Month(d_date) Select Case mm Case 1 mm_con = "มกราคม" Case 2 mm_con = "กุมภาพันธ์" Case 3 mm_con = "มีนาคม" Case 4 mm_con = "เมษายน" Case 5 mm_con = "พฤษภาคม" Case 6 mm_con = "มิถุนายน" Case 7 mm_con = "กรกฎาคม" Case 8 mm_con = "สิงหาคม" Case 9 mm_con = "กันยายน" Case 10 mm_con = "ตุลาคม" Case 11 mm_con = "พฤศจิการยน" Case 12 mm_con = "ธันวาคม" End Select convert_date = Trim(Str(Day(d_date))) + " " + mm_con + " " + Trim(Str(Year(d_date) + 543)) End Function