Question List all days in a given year

dcs.79c

Member
Joined
Feb 21, 2011
Messages
6
Programming Experience
Beginner
I have VB 2010 Express Edition. I also have VB 6 Learning Edition. I am "dotnetizing" my pre-dot net demos. There is a VB3 demo that lists all the days in 1994 in a list box. I can select a specific date & click on a button & that date is displayed in a label.

I've played around with the Date variable & I know that I can use the .now & .today & other methods. I know that I can add days to the current date. I want to be able to start on a specific date & year & list in a list box all of the dates from then until the end of the year. For example, from January 1st, 2010 thru December 31st, 2010.

I know that I can choose a specific date, say, #1/1/2010# & use date.now & get a time span, but that's not what I want to do.

How do I do that or is it even possible?

Thank you.
David
 
Given that you know the Date data type and how to use it to add days, and should know loops. Listbox.Items.Add?? I'll leave that up to you to think over.

In the mean time, let's introduce you to something new in VB. Add a DateTimePicker to a form, doubleclick it and add this code:
VB.NET:
Dim start = Me.DateTimePicker1.Value.Date
Dim daysleft = New Date(start.Year, 12, 31).DayOfYear - start.DayOfYear + 1
Dim dates = Enumerable.Range(0, daysleft).SelectMany(Function(x) {start.AddDays(x)})
Me.DatesListBox.DataSource = dates.ToArray
an alternative to the dates selection could be this, perhaps easier to read:
VB.NET:
dates = From x In Enumerable.Range(0, daysleft) Select start.AddDays(x)
 
I tried the DatePicker code & got the following message:"DatesListBox" is not a member of "WindowsApplication1.Form1". HUH? I don't see a control labeled DatesListBox in the toolbox. Is it not available in the Express Edition?

I'm a firm believer in the "keep it simple" philosophy.

ListBox.Items.Add might work. I'd just use a For..Next loop. But I'd have to take leap years into account.

Reply to kulrom: From my previous post:"There is a VB3 demo that lists all the days in 1994 in a list box. I can select a specific date from the listbox on the form & click on a button on the form & that date is displayed in a label."
 
Can you try something really simple: add a ListBox to your form and give it a reasonable name in the context that it will be a ListBox to contain dates, for example "DatesListBox".
 
Back
Top