CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    14

    array of any month's all date

    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

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: array of any month's all date

    Something like this :

    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured