Re: Counting the Dates
- From: "Larry Serflaten" <serflaten@xxxxxxxxxxxxxx>
- Date: Sun, 27 Jan 2008 02:44:50 -0600
"Webbiz" <noreply@xxxxxxx> wrote
Say you have a file with 10 years of numerical values. One value per
calendar date, excluding weekends and holidays.
January 1, 1997 = 89
January 2, 1997 = 123
January 3, 1997 = 14
...
December 12, 2007 = 77
<...>
So to start off with, I imagine I start by creating an array with 366
elements, one for every day of the year that includes the leap year?
<...>
Would I perhaps first create some sort of table reference, perhaps in a file
or by way of function, that uses MM/DD as the index and references numbers
from 0 to 365, so that each date that is read in would be compared to the
indexes of this table, the element number discovered, and then I'd know
where in my array to add the value to?
Am I making this more complicated than it should be? If you say no, I'd be
very surprised. :-o
Any suggestions or examples?
If it were me, I'd build the array like you say and use a table to convert
the named months to numbers. So, starting with the table, that would be
a Collection where the item is the number and the key is named month:
Table.Add 1, "January"
Table.Add 2, "February"
...
Table.Add 12, "December"
Now the array can be a year's worth of days:
Dim Data(#1/1/1904# To #12/31/1904#) As Long
(You don't care what year the values are from, so I picked 1904 because
it is a leap year and will have the right number of days)
So then as you read the file, you parse out the parts: The month's
name, the month's day, and the value.
name day value
January 1, 1997 = 89
January 2, 1997 = 123
January 3, 1997 = 14
So for that first line, Name = "January", Day = 1 and Value = 89
To add that to the array you'd first get the index:
Dim idx as Date
idx = DateSerial(1904, Table(Name), Day)
(Note that the year 1904 is hard coded, as it was in the Dim statement for Data)
And then add it to whatever is already there:
Data(idx) = Data(idx) + Value
Done with that line, you'd do that for all the lines in the file.
When done, you have the Data array filled with the data you want, and
can iterate through it showing the days and values:
For idx = LBound(Data) To UBound(Data)
Debug.Print Format(idx, "mmm dd") & " = " & Data(idx)
Next
HTH
LFS
.
- References:
- Counting the Dates
- From: Webbiz
- Counting the Dates
- Prev by Date: Re: Counting the Dates
- Next by Date: Metafile, Should I?
- Previous by thread: Re: Counting the Dates
- Next by thread: Re: Counting the Dates
- Index(es):
Relevant Pages
|
Loading