Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 9th, 2003, 03:55 PM
Authorized User
 
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Array Count (Fairly Simple)

Ok, this should be fairly simple... I have an array that contains the following:

114,151,157,151,10,12,14,151,157,10

What I want to do is this: I need to count how many instances of each number show up in this string. Ie the result that I want is this:

114 shows up 1 time
151 shows up 3 times
157 shows up 2 times
10 shows up 2 times
12 shows up 1 time
14 shows up 1 time

Then from there I need to match it back up so I can define this in an orderly fashion..

I.e.
if $variable1 = "114" then $counted1 = "1",
if $variable2 = "151" then $counted2 = "3",
and so-on.

Does any of this make any sense? This is definitely a new one for me.


----------
~cmiller
__________________
----------
~cmiller
 
Old October 9th, 2003, 04:45 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

'Loop thru ALL the items in the source
'array to the find the largest
'Do it this way cause it's most efficient
'to just do this once than to redim many times.
nMax = 0
For i = 0 To UBound(arySource)
    If arySource(i) > nMax Then
        nMax = arySource(i)
    End If
Next
ReDim aryCounts(nMax)
For i = 0 To UBound(arySource)
    aryCounts(arySource(i)) = aryCounts(arySource(i)) + 1
Next

For i = 0 To UBound(aryCounts)
    If aryCounts(i) <> 0 Then
        'Numbers are all ordered for you
        'Do what you need to here
    End If
Next


Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
is there any in built function to count page count g.tamilselvan MySQL 1 February 15th, 2006 07:43 AM
Array count crmpicco Classic ASP Basics 1 June 6th, 2005 09:32 AM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.