Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Last business day of month
Message
De
15/03/2002 06:48:47
Andrew Hanney
Sgai (Ireland) Ltd.
Dublin, Irlande
 
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00631995
Message ID:
00633300
Vues:
19
Hi Al,
I've written some similar code, and have included it below. I hope it will be of some help to you. The function GetLastMonthEnd should return the last working date of the previous month (in my case its for a particular currency code). The function LoadBankHoliday, stores the holdiays in an array.
You will need to have a list of holidays in a table tblBankHoliday for this to work.
Andy.

Function GetLastMonthEnd(sCurr As String) As Date
Dim dEndDate As Date
Dim l As Long
Dim TabHol() As Date 'will hold our list of holidays
Dim b As Boolean
sCurr = "EUR"
l = LoadBankHoliday(sCurr, TabHol)
dEndDate = DateSerial(DatePart("YYYY", Date), DatePart("m", Date), 0)
b = IsBankHoliday(dEndDate, TabHol()) = True Or Weekday(dEndDate) = 7 Or Weekday(dEndDate, vbDate) = 1
Do Until b = False
dEndDate = dEndDate - 1
b = IsBankHoliday(dEndDate, TabHol()) = True Or Weekday(dEndDate) = 7 Or Weekday(dEndDate) = 1
Loop
GetLastMonthEnd = dEndDate
End Function



'------------------------------------------------------------------------
' FUNCTION : IsBankHoliday
'
' PURPOSE : returns a boolean which defines whether a date is a bank holiday
'
' INPUT : d as date : date to check
' BankHoliday() has to be ordered,
' OUTPUT : returns a boolean
'------------------------------------------------------------------------
Public Function IsBankHoliday(ByVal d As Date, ByRef BankHoliday() As Date) As Boolean
Dim lHol As Long

On Error GoTo ErrorIsBankHoliday
IsBankHoliday = False
For lHol = 0 To UBound(BankHoliday)
If BankHoliday(lHol) = d Then
IsBankHoliday = True
Exit For
ElseIf BankHoliday(lHol) > d Then
IsBankHoliday = False
Exit For
End If
Next lHol

Exit Function
ErrorIsBankHoliday:
IsBankHoliday = False
End Function

'------------------------------------------------------------------------
' FUNCTION : LoadBankHoliday
'
' PURPOSE : returns bank holidays from tblBankHoliday
'
' INPUT : Cur as string: currency for the holiday
' BankHoliday() array to fill
'
' OUTPUT : fills BankHoliday
'------------------------------------------------------------------------

Public Function LoadBankHoliday(stCur As String, BankHoliday() As Date) As Long
Dim rs As ADODB.Recordset
Dim l As Long

On Error GoTo ErrorLoadBankHoliday

LoadBankHoliday = 0
Set rs = New ADODB.Recordset
rs.Source = "SELECT * FROM tblBankHoliday WHERE HolCurrency = " & "'" & stCur "'" & " ORDER BY HolDay"
rs.Open , 'your connection here', adOpenStatic, adLockReadOnly, adCmdText
If rs.EOF Then
ReDim BankHoliday(-1 To -1)
Exit Function
Else
ReDim BankHoliday(0 To rs.RecordCount - 1)
l = 0
Do While Not rs.EOF
BankHoliday(l) = rs("HolDay")
l = l + 1
rs.MoveNext
Loop
LoadBankHoliday = l
End If
ErrorLoadBankHoliday:
End Function


tblBankHoliday will look like this
HolCurrency HolDay
CAD 01/01/2002
CAD 29/03/2002
CAD 06/05/2002
CAD 20/05/2002
CAD 27/05/2002
CAD 01/07/2002
CAD 05/08/2002
CAD 02/09/2002
CAD 14/10/2002
CAD 11/11/2002
CAD 25/12/2002
CAD 26/12/2002
USD 01/01/2002
USD 21/01/2002
USD 18/02/2002
USD 27/05/2002
USD 04/07/2002
USD 02/09/2002
USD 14/10/2002
USD 11/11/2002
USD 28/11/2002
USD 25/12/2002
Andrew Hanney
Visual Foxpro programmer/analyst
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform