Molto più intelligente creare una funzione che dia come risultato una matrice di date prendendo sempre come parametri il mese e l'anno.
Eccola:
Module Funzioni Function giorniDelMese(ByVal mese As Integer, ByVal anno As Integer) As Date() Dim data As Date = CDate("01/" & mese & "/" & anno) Dim dataStart As Date = data Dim contatore As Integer = 0 Dim matrice As Date() Do ReDim Preserve matrice(contatore) matrice(contatore) = data data = data.AddDays(1) If data.Month <> dataStart.Month Then Exit Do contatore += 1 Loop Return matrice End Function End Module...e chiamarla dal form iniziale in questo modo:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For n = 0 To giorniDelMese(8, 2012).Length - 1 Debug.Print(giorniDelMese(8, 2012)(n)) Next End Sub...ottenendo il medesimo risultato:
01/08/2012 02/08/2012 03/08/2012 04/08/2012 05/08/2012 06/08/2012 07/08/2012 08/08/2012 09/08/2012 10/08/2012 11/08/2012 12/08/2012 13/08/2012 14/08/2012 15/08/2012 16/08/2012 17/08/2012 18/08/2012 19/08/2012 20/08/2012 21/08/2012 22/08/2012 23/08/2012 24/08/2012 25/08/2012 26/08/2012 27/08/2012 28/08/2012 29/08/2012 30/08/2012 31/08/2012Perfetto!
Nessun commento:
Posta un commento