Adesso ho elaborato io la funzione che trova il numero delle domeniche.
Function sundaysInMonth(anno As Integer, mese As Integer) As Integer
Dim dt As Date
Dim numero As Integer
dt = DateSerial(anno, mese, 1)
Do While Month(dt) = mese
If WeekdayName(Weekday(dt), , 1) = "domenica" Then numero = numero + 1
dt = dt + 1
Loop
sundaysInMonth = numero
End Function
L'ho sperimentato con vari mesi del calendario, e funziona.
Bene.
Adesso ho creato un modulo contenente le funzioni per i calcoli relativi alle date, e l'ho esportato in una cartella.
Ci aggiungo anche questa funzione.
Stabilite le domeniche del mese, facciamo i turni totali, semplicemente:
Sub main()
Dim turniTotali As Integer, anno As Integer, mese As Integer
anno = 2014
mese = 9
turniTotali = daysInMonth(mese, anno) + sundaysInMonth(mese, anno)
MsgBox turniTotali
End Sub
che, ovviamente, dà il numero giusto.Adesso mi resta da attribuire ai due reparti i turni...
Nessun commento:
Posta un commento