Re: Counting the Dates

Tech-Archive recommends: Fix windows errors by optimizing your registry



Steve has a point about the leap years. 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.

Dim Days(12, 31)

I'd go with that, as opposed to the zero-based array of (11, 30), but that'll depend on your needs. Getting from date to array number then becomes quite simple and Feb. 29 is no longer a problem:

Days(Month(MyDate), Day(MyDate)) = _
Days(Month(MyDate), Day(MyDate)) + MyValue

Of course, if you NEED a 1D array, then you have a problem. :) Either convert after you're done, which would be just as much trouble, or don't use a 2D array.


Rob

Webbiz wrote:
I'm trying to solve a problem in the most efficient way. I can solve this problem, but my solution is turtle slow.

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


The first calendar date of the data file does not necessarily start with January 1st of whatever year. It's likely not.

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.

When done, you should have an array that has the total value for January 1, 2, 3, 4, 5, 6, 7... all the way to December 31.

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. When I get back to March 3rd of the next year, this is added to the first March 3rd value and stored in the same element number of the array.

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?

I assume that I'd want to use Array(0) for all the January 1 and Array(365) for all the December 31?

I'm curious if there is a simple way to read the date and quickly determine what the array element would be.

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?

Thank you.

Webbiz

(In case I'm not making sense: I want to add up all the values found under January 1 of each year and place them in the first array element. All the values found under January 2nd of each year and place the total in the second array element, etc.)



.



Relevant Pages

  • Re: Counting the Dates
    ... 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 ... (In case I'm not making sense: I want to add up all the values found ... under January 1 of each year and place them in the first array element. ...
    (microsoft.public.vb.general.discussion)
  • Re: Base64-Encoding
    ... -- Pad input data to 3-Byte boundary. ... -- Overlay array of six-bit tokens over the padded input data. ... You're hoping for a representation of an array of 6-bit integers, ... the second array element is such that the two high ...
    (comp.lang.ada)
  • Re: Bugs at my web site
    ... "7.2.1.1.1 Array Element Successor Function and Value of a Subscript. ...
    (comp.lang.fortran)
  • Counting the Dates
    ... So you start reading the data file, adding up all the values that fall on ... When done, you should have an array that has the total value for January 1, ... (In case I'm not making sense: I want to add up all the values found under ... January 1 of each year and place them in the first array element. ...
    (microsoft.public.vb.general.discussion)
  • Re: An inefficiency in Array.Sort
    ... You are failing to appreciate the distinction I am trying to make between comparison of two array elelements and the comparison of two values. ... A comparison of an array element to itself - comparing ato aas you put it - would clearly be inefficient, as the routine should know that the i values were equal and therefore there is no need to use the icomparer. ... These comparisons are common to most sorting routines, either because of the use of temporaries or because the sort operation itself renders comparisons of the i value meaningless. ...
    (microsoft.public.dotnet.languages.vb)