Click to See Complete Forum and Search --> : array of any month's all date


devilz
April 21st, 2010, 06:41 PM
Hello readers,

i need to populate all date for an specific month selected by the user from a combo box where i added all months name. can any one let me know that how i can create array of any months of the year, very new coder in vb.Net. hope you will guide me. plz.. plz...plz....

regards

HanneSThEGreaT
April 22nd, 2010, 03:08 AM
Something like this :

Public Class Form1
Dim dtSel As Date = DateTime.Now
Dim NumDays As Integer
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
NumDays = dtSel.DaysInMonth(DateTime.Now.Year, ComboBox1.SelectedIndex + 1)

ComboBox2.Items.Clear()
For i As Integer = 1 To NumDays
ComboBox2.Items.Add(i)
Next
End Sub
End Class

Just add 2 ComboBoxes to the form. The trick is in the Date object's DaysInMonth method, which uses the curent year, as well as the current month's selection. Why I said +1, is because arrays start at 0 and there is no month zero