Array value range

Started by seckner, February 06, 2015, 12:30:51 PM

Previous topic - Next topic

seckner

We receive orders throughout the day and those files go into a directory. Using FileInfoToArray ("*.*") I create an array and then sort it. The goal is to create a very brief report that simply summarizes number of orders by hour. To get it done I'm currently going row by row, extract the modified time and see if it's between hour 00:00 and 01:00, count those that are. Then hour 01:00 to 02:00, and on and on. Is there a way, using the array, to search for all of the between 00:00 and 01:00 or 01:00 and 02:00, etc. When we get up to 400 orders between 18:00 and 19:00 and so on this is pretty slow.

Is there a more efficient way to do this?   

JTaylor

Fabricated RecordSet or import to a database? 

Jim

kdmoyers

I suggest one pass through the filearray totalling to a second array indexed by hour number. I'm guessing for 10K files, that might take half a second.  The FileInfoToArray statement itself will take 10x longer than the totalling operation anyway, since it will be IO bound.  Fortunately, you only have to do that once.

$0.02,
Kirby
The mind is everything; What you think, you become.

td

Assuming that the array is sorted on the modify date column using ArraySort, the single pass approach should be relatively efficient.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

even if it were not sorted, you could total into another array that is indexed by the hour number.  that way, even if the files were in random order, after one pass, you would have all the totals.

for each file
  h = hour number of this file
  tarray[h] = tarray[h] + 1
next file

right? or am i missing something.
The mind is everything; What you think, you become.

td

I don't think you missed anything.  I am the one that missed something.  ArraySort is very efficient and there are a few cute tricks that you can sometime use with ArraySearch on sorted arrays to avoid having to iterate tens of thousands of times ( it is no secret that WIL loops are big time time burners.)  However, after a morning cup or three, it is apparent that having WIL dates  in the targeted field throws a wrench into the whole idea unless you can make some fairly unrealistic assumptions about the file dates in those fields. 

This problem does make a case for being able to perform linear wild card searches of arrays... 

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade