HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 31st, 2004, 02:55 PM
unicorn unicorn is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Northern Ireland
Posts: 63 unicorn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 47 m 50 sec
Reputation Power: 5
Array Sort

OK Shadow...this sorting that I've been at for the last two days !....
After a lot of 'my own' coding, looking at the problem from scratch and trying to code it, I've given up on my own code.

The senario is ..I have two arrays (which I could make a single multidimensional array I suppose), but anyway sticking to my two arrays, each array entry is linked, i.e. array1(1) must always 'go along with' array2(1), and in array1 there is a list of names..in array2 there are numbers....array1 can have multiple entries of the same name, with different numbers in the same locations in array2...I have finally found the code below which deletes the multiple names from array1, but now i have to figure out how to add the numbers associated with the multiple same names in array1 from array2 and put the result in the same place in array2 as the name left in array1 which had multiple entries, and delete the entries from array2 which are not now associated with their partners in array1 as they have been deleted....maybe thats not very clear , and after writing this I can see a multidimensional array is what I need....

eg array1 array2
jointing 94.56
aerial 8
react 10.51
react 56
poling 13.41

would end up

array1 array2
jointing 94.56
aerial 8
react 66.51
poling 13.41

dim retvalues()
redim preserve retvalues(1)
retvalues(0)=SkillType(0)

For I=0 to (UBound(SkillType)-1)

dim result
result=0

For y=0 to (ubound(retvalues)-1)
result=StrComp(SkillType(I),retvalues(y),1)
if (result=0) then
exit for
end if

Next

if(result<>0)then
redim preserve retvalues(ubound(retvalues)+1)
retvalues(ubound(retvalues)-1)=SkillType(I)
end if

Next

Reply With Quote
  #2  
Old November 1st, 2004, 01:18 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
the Dictionary object would be perfect for your case. using this, there is quite simple code to merge the arrays:
Code:
  <%
   Function MergeArrays(arr1, arr2, ByRef objDic)
 	'this function fills the given dictionary object with the unique items from arr1 as keys and the sum of associated items from arr2 as value.
  	'both arrays must be in same size.
  	'returns Empty if successful or error message on failure.
  	
  	'verify same size:
  	If Not(UBound(arr1)=UBound(arr2)) Then
 	 MergeArrays="Error: arrays are not of the same size. first array has "&(UBound(arr1)+1)&" items and second array has "&(UBound(arr2)+1)&" items."
  	   Exit Function
  	End If
  	
  	Dim x
  	Set objDic=Server.CreateObject("Scripting.Dictionary")
  	
  	'loop over arrays:
  	For x=0 To UBound(arr1)
  	   'verify numeric value in second array:
  	   If Not(IsNumeric(arr2(x))) Then
  		  objDic.RemoveAll
  		  Set objDic=Nothing
  		  MergeArrays="Error: found invalid item in second array: "&arr2(x)
  		  Exit Function
  	   End If
  	   'apply second array value into dictionary:
  	   If objDic.Exists(LCase(arr1(x))) Then
  		  objDic(LCase(arr1(x))) = objDic(LCase(arr1(x)))+CDbl(arr2(x))
  	   Else  
  		  objDic(arr1(x))=CDbl(arr2(x))
  	   End If
  	Next
   End Function
   
   'usage:
   Dim array1, array2, myDic
   Dim strErrorMsg, key
   array1=Array("jointing", "aerial", "react", "react", "poling")
   array2=Array(94.56, 8, 10.51, 56, 13.41)
   strErrorMsg=MergeArrays(array1, array2, myDic)
   If Len(strErrorMsg)>0 Then
  	Response.Write("error while merging arrays: <br />"&strErrorMsg&"<br />")
   Else 
  	Response.Write("merged arrays:<br />")
  	For Each key In myDic.Keys
  	   Response.Write(key&" - "&myDic(key)&"<br />")
  	Next
   End If
  %>
  

Reply With Quote
  #3  
Old November 2nd, 2004, 12:42 PM
unicorn unicorn is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Northern Ireland
Posts: 63 unicorn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 47 m 50 sec
Reputation Power: 5
Array sort

Excellent Shadow.......works a treat...i just changed a few things to make it work in my live enviornment...so thats that prob out of the way..onto the next.....will now continue coding some other pages before i need help again (I think) ....many thanks for the code....cul....>>>

Reply With Quote
  #4  
Old November 2nd, 2004, 02:38 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
no problem... add another drink to the stash!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Array Sort


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway