10 Replies - 780 Views - Last Post: 14 April 2011 - 08:01 AM Rate Topic: -----

#1 AN1554  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 130
  • Joined: 03-April 11

Display all the dates in one year

Posted 11 April 2011 - 08:10 AM

The program: display all the dates in one year in a listbox (normal year, not leap year), i.e. from 1 January to 31 December. The question says to use For...Next loop to handle the whole year and inside it use Select Case to handle each month. I'm not too sure what this means, though.

I'm working on it, trying to find a solution for the program, but I don't have any idea really on how to do this. :helpsmilie: Any help would be greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Display all the dates in one year

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,473
  • Joined: 12-June 08

Re: Display all the dates in one year

Posted 11 April 2011 - 08:23 AM

It would seem that a for loop for the entire year would be what? Each day? The case statement would take the numerical day and find the month. Output both and the year, repeat loop, increment day loop control variable.
Was This Post Helpful? 0
  • +
  • -

#3 AN1554  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 130
  • Joined: 03-April 11

Re: Display all the dates in one year

Posted 11 April 2011 - 09:51 AM

I found it. I wanted something that would make the month automatically go from January to February and so on but I don't know how that's possible. My solution is simple but quite tiring for having to type the month name and number of days in each month.

Private Sub Form_Load()

    Dim NumberOfMonth As Integer
    Dim Month As String
    Dim MaxDays As Integer
    Dim Day As Integer
    
    For NumberOfMonth = 1 To 12
        Select Case NumberOfMonth
            Case 1
                Month = "January"
                MaxDays = 31
            Case 2
                Month = "February"
                MaxDays = 28
            Case 3
                Month = "March"
                MaxDays = 31
            Case 4
                Month = "April"
                MaxDays = 30
            Case 5
                Month = "May"
                MaxDays = 31
            Case 6
                Month = "June"
                MaxDays = 30
            Case 7
                Month = "July"
                MaxDays = 31
            Case 8
                Month = "August"
                MaxDays = 31
            Case 9
                Month = "September"
                MaxDays = 30
            Case 10
                Month = "October"
                MaxDays = 31
            Case 11
                Month = "November"
                MaxDays = 30
            Case 12
                Month = "December"
                MaxDays = 31
            End Select
        For Day = 1 To MaxDays
            lstCalendar.AddItem Day & " " & Month
        Next Day
    Next NumberOfMonth
    
End Sub

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,473
  • Joined: 12-June 08

Re: Display all the dates in one year

Posted 11 April 2011 - 10:00 AM

Well - that shows you there are multiple paths to the same solution!

For my future reference - why was I down repped?

This post has been edited by modi123_1: 11 April 2011 - 10:01 AM

Was This Post Helpful? 0
  • +
  • -

#5 AN1554  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 130
  • Joined: 03-April 11

Re: Display all the dates in one year

Posted 11 April 2011 - 10:21 AM

Your post wasn't helpful :P. It didn't help me to find a solution to the program because I don't understand what you meant. Maybe I should have asked you what you meant -_- Sorry about that. I had already found the answer then :P. But for your future reference - erm, be clearer when you explain. Hope you didn't take the down rep wrong...
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,473
  • Joined: 12-June 08

Re: Display all the dates in one year

Posted 11 April 2011 - 10:44 AM

Cool. Will do. I'll file this in my little black book:
- 'when responding to "I don't have any idea really on how to do this." I should be more clear in my attempts at answering".

lullz, gullz, and kittenz! :neat:
Was This Post Helpful? 0
  • +
  • -

#7 maj3091  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: Display all the dates in one year

Posted 11 April 2011 - 11:32 AM

A bit unfair to mark Modi down, as the response was based on what you'd given as information and it was a pointer on one way to do it, which would've given exactly the same output as your solution did.
Was This Post Helpful? 0
  • +
  • -

#8 AN1554  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 130
  • Joined: 03-April 11

Re: Display all the dates in one year

Posted 11 April 2011 - 12:29 PM

View Postmodi123_1, on 11 April 2011 - 10:44 AM, said:

Cool. Will do. I'll file this in my little black book:
- 'when responding to "I don't have any idea really on how to do this." I should be more clear in my attempts at answering".

lullz, gullz, and kittenz! :neat:


Lol :)

View Postmaj3091, on 11 April 2011 - 11:32 AM, said:

A bit unfair to mark Modi down, as the response was based on what you'd given as information and it was a pointer on one way to do it, which would've given exactly the same output as your solution did.


As I said, I should have asked Modi what he meant. I didn't understand what Modi meant... Next time, I'll be more careful. :sweatdrop:
Was This Post Helpful? 0
  • +
  • -

#9 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: Display all the dates in one year

Posted 11 April 2011 - 06:29 PM

For your future refrerence, An, if you downrep people who are trying to help you it's unlikely that they will help you again. I wouldn't downrep anyone unless they were wasting my time and I wanted to make sure that they quit bothering me, or if they were terminally sincere help vampires.
Was This Post Helpful? 0
  • +
  • -

#10 AN1554  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 130
  • Joined: 03-April 11

Re: Display all the dates in one year

Posted 14 April 2011 - 07:24 AM

Ok, that'll be my fault then, if the person doesn't help me next time... I've understood I shouldn't have down repped him :| Sorry, Modi.

Concerning what I wanted exactly for the program, I've found it. There's a function called MonthName. E.g.: MonthName(1) will return "January", MonthName(2) will return "February" and so on.

This post has been edited by AN1554: 14 April 2011 - 07:28 AM

Was This Post Helpful? 0
  • +
  • -

#11 AN1554  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 130
  • Joined: 03-April 11

Re: Display all the dates in one year

Posted 14 April 2011 - 08:01 AM

And MonthName is the ultimate solution! :clap: ^^

My code is now much shorter and simpler.

Private Sub Form_Load()

    Dim NumberOfMonth As Integer
    Dim Month As String
    Dim MaxDays As Integer
    Dim Day As Integer
 
    For NumberOfMonth = 1 To 12
        Select Case NumberOfMonth
            Case 1, 3, 5, 7, 8, 10, 12
                MaxDays = 31
            Case 2
                MaxDays = 28
            Case 4, 6, 9, 11
                MaxDays = 30
        End Select
        For Day = 1 To MaxDays
            lstCalendar.AddItem Day & " " & MonthName(NumberOfMonth)
        Next Day
    Next NumberOfMonth
End Sub

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1