home *** CD-ROM | disk | FTP | other *** search
/ com!online 2001 December / COMCD1201.iso / openoffice / f_0031 / BankHoliday.xba next >
Encoding:
Extensible Markup Language  |  2001-07-20  |  4.4 KB  |  162 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="BankHoliday" script:language="StarBasic">Option Explicit
  4.  
  5. Sub Main()
  6.     Call CalAutopilotTable()
  7. End Sub
  8.  
  9.  
  10. Function CalEasterTable&(byval Year%)
  11.  
  12.     Dim   B,C,D,E,F,G,H,I,K,L,M,N,O, nMonth, nDay As Integer
  13.  
  14.        N = Year% mod 19
  15.        B = int(Year% / 100)
  16.        C = Year% mod 100
  17.        D = int(B / 4)
  18.        E = B mod 4
  19.        F = int((B + 8) / 25)
  20.        G = int((B - F + 1) / 3)
  21.        H =(19 * N + B - D - G + 15) mod 30
  22.        I = int(C / 4)
  23.        K = C mod 4
  24.        L =(32 + 2 * E + 2 * I - H - K) mod 7
  25.        M = int((N + 11 * H + 22 * L) / 451)
  26.        O = H + L - 7 * M + 114
  27.        nDay = O mod 31 + 1
  28.        nMonth = int(O / 31)
  29.        CalEasterTable& = DateSerial(Year%, nMonth,nDay)
  30. End Function
  31.  
  32.  
  33.  
  34. Sub CalInitGlobalVariablesDate()
  35. Dim i as Integer
  36.  
  37.     For i = 1 To 374
  38.         CalBankholidayName$(i) = ""
  39.         CalTypeOfBankHoliday%(i) = cHolidayType_None
  40.     Next
  41. End Sub
  42.  
  43.  
  44.  
  45. Sub CalInsertBankholiday(byval actDate&, byval Event$, ByVal nBankholidayLevel%)
  46.     Dim DayInYear%
  47.     '    Fuegt ein Ereignis in das globale EventArray ein.
  48.     '    Der Sonderfall der eintreten kann, ist der, dass das Datum
  49.     '    an dem eingefuegt werden soll, bereits ein Ereignis enthaelt.
  50.     '    Dann werden beide Ereignisse mit einem Schraegstrich verbunden.
  51.     DayInYear% =(Month(actDate&)-1)*31 +Day(actDate&)
  52.  
  53.     '    Hoehere Prioritaet des Feiertagtyps
  54.     If (0 <> CalTypeOfBankHoliday%(DayInYear%)) Then
  55.         If (nBankholidayLevel% < CalTypeOfBankHoliday%(DayInYear%)) Then
  56.             CalTypeOfBankHoliday%(DayInYear%) = nBankholidayLevel%
  57.         End If
  58.     Else
  59.         CalTypeOfBankHoliday%(DayInYear%) = nBankholidayLevel%
  60.     End If
  61.  
  62.     If (CalBankHolidayName$(DayInYear%) = "") Then
  63.         CalBankHolidayName$(DayInYear%) = Event$
  64.     Else
  65.         CalBankHolidayName$(DayInYear%) = CalBankHolidayName$(DayInYear%) + " / " + Event$
  66.     End If
  67. End Sub
  68.  
  69.  
  70.  
  71. Function CalIsLeapYear%(ByVal TheYear%)
  72.     CalIsLeapYear% = TheYear Mod 4 = 0
  73. End Function
  74.  
  75.  
  76. Function CalMaxDayInMonth%(byval YearVal%, byval MonthVal%)
  77.     '    Liefert den maximalen Tag eines Monats in einem
  78.     '    bestimmten Jahr.
  79.  
  80.     Dim tmpDate&
  81.     Dim    MaxDay%
  82.     
  83.     MaxDay = 28
  84.     tmpDate& = DateSerial(YearVal%, MonthVal%, MaxDay)
  85.     
  86.     While Month(tmpDate&) = MonthVal%
  87.         MaxDay% = MaxDay% + 1
  88.         tmpDate& = tmpDate& + 1
  89.     Wend
  90.     Maxday% = MaxDay% - 1
  91.     CalMaxDayInMonth% = MaxDay%    
  92. End Function
  93.  
  94.  
  95. Function CalGetIntOfShortMonthName%(byval MonthName$)
  96. Dim i as Integer
  97. Dim nMonth as Integer
  98.     
  99.     nMonth = Val(MonthName$)
  100.     
  101.     If (1 <= nMonth And 12 >= nMonth) Then
  102.         CalGetIntOfShortMonthName% = nMonth
  103.         Exit Function
  104.     End If    
  105.     
  106.     MonthName$ = UCase(Trim(Left(MonthName, 3)))
  107.  
  108.     For i = 1 To 12 
  109.         If (UCase(cCalShortMonthNames$(i)) = MonthName$) Then
  110.             CalGetIntOfShortMonthName% = i
  111.             Exit Function
  112.         End If
  113.     Next
  114.     
  115.     '    Not Found
  116.     CalGetIntOfShortMonthName% = 0
  117. End Function
  118.  
  119.  
  120. Sub CalInsertOwnDataInTables(byval YearToInsert%)
  121.     '    F├╝gt die eigenen Individuellen Daten aus der Tabelle in die
  122.     '    bereits erstellte unsortierte Tabelle ein.    
  123. Dim CurEventName as String
  124. Dim CurYear as Integer
  125. Dim CurMonth as Integer
  126. Dim CurDay as Integer
  127. Dim LastIndex as Integer
  128. Dim i as Integer
  129.     LastIndex = Ubound(DlgCalModel.lstOwnData.StringItemList())
  130.     For i = 0 To LastIndex
  131.         CurYear = CalGetYearOfEvent(i)
  132.         If (CurYear = YearToInsert) Or (CurYear = 0) Then
  133.             CurMonth = CalGetMonthofEvent(i)
  134.             CurDay = CalGetDayofEvent(i)
  135.             CurEventName = CalGetNameOfEvent(i)
  136.             CalInsertBankholiday(DateSerial(CurYear, CurMonth, CurDay), CurEventName, cHolidayType_Own)
  137.         End If
  138.     Next
  139. End Sub
  140.  
  141.  
  142. ' Finds eg the first,second Monday in a month
  143. ' Note: in This Function the week starts with the Sunday
  144. Function GetMonthDate(iWeekDay, iMonth, iCount as Integer)
  145. Dim bFound as Boolean
  146. Dim i as Integer
  147. Dim lDate as Integer
  148.     '    1st Tue in Nov : Election Day, Half
  149.     bFound = False
  150.     i = 0
  151.     lDate = DateSerial(YearInt%, iMonth, 1)
  152.     While Not bFound
  153.         If (iWeekDay = WeekDay(lDate)) Then i = i + 1
  154.         If (i < iCount) Then
  155.             lDate = lDate + 1
  156.         Else
  157.             bFound = True
  158.         End If
  159.     Wend
  160.     GetMonthDate = lDate
  161. End Function
  162. </script:module>