Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2005
    Posts
    45

    Unanswered: Quickest way to count values in array

    I am using getrows to assign a recordset to an array, and am wondering the quickest way to get a count of the values in the array.

    Do I need to look from LBound to UBound, or is there a quicker way?

    Thanks!

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    How is UBound not fast enough?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Dec 2005
    Posts
    45
    Sorry, it is. I just thought there might be something similar to 'rs.recordcount' for arrays.

    I'm building an Access application, but it doesn't look like vb will be able to do the job quickly enough, so I'm trying to save as much time as possible.

    Thanks!

  4. #4
    Join Date
    Mar 2006
    Location
    south jersey, usa
    Posts
    53
    (Ubound(arr, 2) - 1) will output the record count

    - 1 because arrays are zero-based
    "They say Moses split the Red Sea
    I split the blunt and rolled the fat one, I'm deadly"
    -- Tupac 'Blasphemy'

  5. #5
    Join Date
    Dec 2005
    Posts
    45
    Thanks csamules. Just what I was looking for.

    Don't know if there will be a noticable performance difference, but...

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by csamuels
    .... arrays are zero-based
    Not necessarily. But usually
    Testimonial:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    air guess: the execution time-difference between
    Ubound()-1 (if indeed you have used the default 0-base index pace Pootle)
    and
    Ubound()-Lbound()
    is well below one millionth of a second and probably in the range of a few billionths of a second
    - we wont get rich that way.

    you may save a few extra billionths of a second by declaring your arrays 1 To N so that the naked Ubound() saves Access one memory lookup and one integer maths subtraction.

    billionths of a second and 1000 accounts: the delta can't be more than a millisecond either way.
    ...why are we talking about this stuff????????

    izy
    currently using SS 2008R2

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by izyrider
    air guess: the execution time-difference between
    Ubound()-1 (if indeed you have used the default 0-base index pace Pootle)
    and
    Ubound()-Lbound()
    is well below one millionth of a second and probably in the range of a few billionths of a second
    - we wont get rich that way.

    you may save a few extra billionths of a second by declaring your arrays 1 To N so that the naked Ubound() saves Access one memory lookup and one integer maths subtraction.

    billionths of a second and 1000 accounts: the delta can't be more than a millisecond either way.
    ...why are we talking about this stuff????????

    izy
    Lol. You been on the red wine again Izy?

    pace... I guess I am just far too ignorant to understand that one? Classical?... French?... Um... Swiss?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  9. #9
    Join Date
    Dec 2005
    Posts
    45
    izyrider,

    I think that had you replied, "The difference will be too minimal to notice", you would have saved yourself the very 'talking about this stuff' you seem to regret. Besides, I said 1000 accounts, but hundreds of thousands of records.

    I'm trying to build an app that performs well enough that it will be viable in production. Using tables and queries on the front end is not sufficient, and I believe arrays are my only option (in Access, at least).

  10. #10
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    latin.
    ablative of pax: peace
    used above in the sense of "with deference to"

    ...and yes, saturday night is red wine night, so there was an error:
    one memory lookup and one integer maths subtraction
    should have read
    one memory lookup and one integer maths subtraction or one integer maths subtraction of a constant (the latter should be faster by a billionth or two of a second, of course)

    ironically, i've been beating my head against the screen all day playing with an array-based algo. this one really wont work with SQL (or the 'set-based' approach in your tekkie jargon) since i'm brute-forcing a few hundred million attempts to find a best fit by loop(loop(loop(loop)))-ing through a bunch of small arrays starting at each possible starting index in each array. i have bugs to spare! just started the third clean-slate rewrite an hour ago.

    izy
    currently using SS 2008R2

  11. #11
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    HeavyBall: my redwine explanation crossed with your post. i get talkative after a glass or two (and to make it worse i'm really crosseyed after a day of fighting with arrays. i wish there was a fast seek/find/search in arrays!)

    izy
    currently using SS 2008R2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •