Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Displaying Previous six months/year

Posted on 2004-08-01
4
Medium Priority
?
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Make the most of your online learning experience.
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…
Simple Linear Regression

670 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