Solved

Displaying Previous six months/year

Posted on 2004-08-01
4
227 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 63
Non-recursive backtracking, using a stack 1 101
silent install of security banner via msiexec command 4 74
C# code editing and collaboration 3 98
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

912 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now