Results 1 to 4 of 4

Thread: Count the each element in an array

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513

    Question Count the each element in an array

    I have an array and when I display the array, it looks like this:

    Group1
    Dave
    John
    Dave
    Mike
    Mike
    Leo
    Amos
    Brian
    Dave

    I want to have it displayed like this:

    Group1
    Dave 3
    John 1
    Mike 2
    Leo 1
    Amos 1
    Brian 1

    Here is my code at the moment to display as in the first example:

    <u>Group1</u><br>
    <%for i=1 to Var10%>
    <%=Var10P(i)%><br>
    <%next%>

  2. #2
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796
    Can you use a database?

    Insert the values of the array into a table and then do a GroupBy query to count the number of occurences of each name.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513
    I prefer not to use a database...

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    You could do it with two arrays...

    Loop eveyname in your primary array.

    Create/update an array with the counts of names...

    Sya "BOB" is the current arry entry. Loop thru the second arry trying to find "BOB". If it's not in there, add the name with COUNT of 1, if it is in there, add to the count.

    Note : If alot of names, this will be slow. Suggest using database, too.
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

Posting Permissions

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



Click Here to Expand Forum to Full Width