Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 9th, 2003, 03:55 PM
Authorized User
Join Date: Jun 2003
Location: San Jose, CA, USA.
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:


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..

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.

Reply With Quote
  #2 (permalink)  
Old October 9th, 2003, 04:45 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

'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
ReDim aryCounts(nMax)
For i = 0 To UBound(arySource)
    aryCounts(arySource(i)) = aryCounts(arySource(i)) + 1

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

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 02:42 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.