Solved

Displaying Previous six months/year

Posted on 2004-08-01
4
230 Views
Last Modified: 2010-04-17
Hi
I want to display previous 6 months along with the year in a drop down list. How would I do it?. I can display months of the year But does not work if the month  is february 2004, The drop down just lists jan and February of  2004, While I want the display from september 2003 to Feb 2004.

Thanks

Any help would be helpful.
Thanks
Madhavi
0
Comment
Question by:ChanderMadhavi
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 11691068
Hi,
Please paste your code here.

-FA
0
 

Author Comment

by:ChanderMadhavi
ID: 11691192
The basic code is here
            Dim intX As Integer
            intX = Month(Now)   'Displays month
            While intX <> 0
                ddLstMonth.Items.Add(MonthName(intX))
                intX -= 1
            End While
'This works fine if month is after june. If before june it displays only till jan. I always want to display 6 previous months irrespective of the month of the year. I also just want to restrict the month display to previous 6 months only
0
 
LVL 4

Expert Comment

by:rohanpandya
ID: 11691208
Hi

 Use following

         Dim i As Integer = 0
            Dim dt As Date = "4 / 23 / 2004"
            Dim item As String
            For i = 0 To 5
                  If dt.Month - i > 0 Then
                        item = dt.Month - i & dt.Year
                        cmbTest.Items.Add(item)
                  Else
                        item = dt.Month - i + 12 & dt.Year - 1
                        cmbTest.Items.Add(item)
                  End If
            Next

 Here you not get the name of the month but number of month but you can do it for name of the month also

 try it
0
 
LVL 4

Accepted Solution

by:
rohanpandya earned 125 total points
ID: 11691218
following is for the name of the month

  Dim i As Integer = 0
            Dim dt As Date = "4 / 23 / 2004"
            Dim item As String
            For i = 0 To 5
                  If dt.Month - i > 0 Then
                        item = MonthName(dt.Month - i) & dt.Year
                        cmbTest.Items.Add(item)
                  Else
                        item = MonthName(dt.Month - i + 12) & dt.Year - 1
                        cmbTest.Items.Add(item)
                  End If
            Next

      it's work you can select any dt in Date variable dt
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 70
some keys in my laptop is not working. any suggestion 6 47
Where to download python requests library 6 61
Java List 4 32
In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question