Re: Counting the Dates




"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



.



Relevant Pages

  • Re: Counting the Dates
    ... The other way to structure it, which bypasses the problem with leap years, but may or may not be useful to you is to use a two-dimensional array instead of one. ... So you start reading the data file, adding up all the values that fall on the same Month and Day of each year that you have in the file. ... In other words, if I have 10 years of data and my data file starts with March 3rd 1997, I start by placing the value for March 3rd in an array element, then the 4th, 5th, etc. ...
    (microsoft.public.vb.general.discussion)
  • Re: Counting the Dates
    ... Webbiz wrote: ... I imagine I start by creating an array with 366 ... days after Feb 29 in a leap year will come back 1 higher than their ...
    (microsoft.public.vb.general.discussion)
  • Re: Counting the Dates
    ... I imagine I start by creating an array with 366 ... days after Feb 29 in a leap year will come back 1 higher than ... see if you need to make the correction. ...
    (microsoft.public.vb.general.discussion)
  • Re: i write a date calculator, but there always get a one-day-distance wrong
    ... check ine year is a leap year, and return the month day array ... OMG man, you should to rewrite this code... ...
    (comp.lang.php)
  • Re: some bit math help
    ... > bits within the 128 chars-length string and past the settings as a VB ... As others suggested a Byte array would be more suitable for this ... Offsets Index, idx, bit ...
    (microsoft.public.vb.general.discussion)

Loading