Problem filling an array..
First time posting here..
First off this is a college assignment and i'm not looking for a quick fix here just some direction.
I have to take a year (int) from user and then print out the calendar for that year. Months: 3 Across 4 Down.
I am trying to fill a 12 2D Array 1 2D Element for each month.
It should look like: < array element >
JANUARY ------------ <0>
Mo Tu We Th Fr Sa Su <1>
1 2 3 4 5 6 <2>
7 8 9 10 11 12 13 <3>
14 15 16 17 18 19 20 <4>
21 22 23 24 25 26 27 <5>
28 29 30 31 <6>
--filled with spaces--- <7>
My problem is filling elements elements 2 to 7. If on the first week the first day is different each month how can I tell what the first day of the second week is going to be?
I have tried many things and it frying my head because it is a really early problem and can't go any further if I can't fix this.
Any ideas? Oh yeah i'm not really looking for code on how to do this..just logical advice..
How are you storing/determining the historical data (what day of the week Jan 1 is for the given year)? That determines which element holds "1" in row 2.
the first element in row 3 is one more than the last element in row 2.
Have you seen those "perpetual calendars"? If you want the calendar for 1985, look at calendar #x, which is the same as 1993 and 2007? This is the perfect kind of data for a lookup table(s) and stored data setup, which is stored in files and loaded into memory upon request (if this was a production kind of program).
I will be using a function to determine what day of the week Jan 1 is.
How would I go about a routine that would check the last date of the previous row and add one for the beginning of the next row??
To get the value for row 3, column 0, you would query row 2 column 6, determine the value held there, add 1, insert the value as a string(?), keep count
OR - just have a dayOfTheMonth variable that is incremented as soon as it is assigned to a location in your 2D array, then when you go to your new location (let's say, Sunday/Monday of your next week) you would just read the value of dayOfTheMonth and insert that value at the new location, then increment dayOfTheMonth and read that into the next location, etc., continuing while dayOfTheMonth is less than or equal to the daysInTheMonth value for the given month which you've read from a table.
Last Post: 04-01-2007, 07:32 PM
Last Post: 03-31-2007, 05:11 PM
Last Post: 10-30-2002, 05:40 AM
Last Post: 10-15-2002, 03:58 PM
By Narayan in forum VB Classic
Last Post: 06-20-2001, 08:56 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center