Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sumif in Array

Status
Not open for further replies.

AlaskanDad

Programmer
Mar 1, 2002
188
US
I know how I would do this in SQL but I have an array with ID numbers and a specific instance that looks like this:

7083 1
5616 1
7225 1
7052 1
3975 1
1 8
5616 1
5616 1
5086 1
7083 1
5616 1
7225 1
7052 1
3975 1
1 8
5616 1
5616 1
5086 1
7083 1

And I would like to make it into an array with summarized ID's and summed instances that looks like this:

7083 3
5616 6
7225 2
7052 2
3975 2
1 16
5086 2

How can you do this with arrays?

Thanks,
Rob
 
not directly, but is this '7083 1' one value?

Known is handfull, Unknown is worldfull
 
The first number is an ID number, the second is a single instance or occurence.

Member 7083 had a total of 3 instances, Member 1 had a total of 16 instances.

Update:
I made this work by checking to see if the ID number existed in the array before I added it. If it did exist already, I increased the number of instances by one. If it didn't exist, I ReDim-ed the array and added the ID number and an instance of 1.
 
You could do that using SQL directlym should be much faster.
Also you can do this using array's
Code:
set dic=Server.CreateObject("Scripting.Dictionary")

'repeat for all your ID's
if dic.Exists(newID)
'if exists add the value to it
 dic(newID)=dic(newID)+newVal
else
'if doesnt exists add to list
 dic.Add newID,newVal
end if

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top