Public Function NthDayOfMonth( _ intMonth As Integer, _ intYear As Integer, _ intOccurrence As Integer, _ intDay As Integer) _ As Variant \' Comments : Returns the date of the Nth day (Monday, Tuesday, etc.) \' of the month \' Parameters: intMonth - month to check \' intYear - year to check \' Note: Always specify the full four digits of the year \' or the code cannot be considered Year 2000 compliant. \' intOccurrence - the occurrence number of the day \' to calculate (1 for first, 2 for second, etc.) \' intDay - the day of the week to calculate (1 for Sunday, \' 2 for Monday, etc.) \' Returns : Nth day of month (null if date does not exist) \' Dim varTempDate As Variant Dim intCurrDay As Integer
On Error GoTo PROC_ERR
varTempDate = DateSerial(intYear, intMonth, 1)
If (intDay > 0) And (intDay < 8) And (intOccurrence > 0) Then
\' Calculate first intDay of the month. intCurrDay = Weekday(varTempDate)
If intCurrDay <> intDay Then
If intCurrDay < intDay Then varTempDate = varTempDate + (intDay - intCurrDay) Else varTempDate = varTempDate + (7 + intDay - intCurrDay) End If
End If
If intOccurrence > 1 Then varTempDate = varTempDate + 7 * (intOccurrence - 1)
If Month(varTempDate) <> intMonth Then \' Date goes past month varTempDate = Null End If
Skulle måske tilføje, at datovalg hidrører fra anvendelse af mscal.oxc, men det er jo underordnet. Se tillige ugenr. - noget jeg brugte 40 kodelinier til i VB3.
johnfs>> Funktionen fungerer, men Datepart er nemmere at bruge, som joern foreslår. Anyways, jeg deler pointene mellem jer.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.