Forum Moderators: open

Message Too Old, No Replies

help using ASP dictionary object

         

musicales

2:32 pm on Mar 31, 2006 (gmt 0)

10+ Year Member



I'm a bit rusty on my ASP Dictionary Object. I have an unsorted array and I want to chuck it into a dictionary object and sort it alphabetically. Can anyone help remind me how to do this?

Easy_Coder

8:26 pm on Mar 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you gotta roll your own sort with that object.

Demaestro

8:27 pm on Mar 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there a lambda() function available to you?

carguy84

1:59 am on Apr 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can just loop the array into a dictionary.

Chip-

Easy_Coder

2:17 am on Apr 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you can sort the array then I think you need to stuff it in descending order; then the dictionary will unwind it in ascending order.

Is your array populated from a database? It'd be much simpler to sort there.

musicales

7:16 am on Apr 1, 2006 (gmt 0)

10+ Year Member



easy - it's one of the rare ocassions it's not. I thought I remembered a sort function/method for dictionaries but maybe I'm wrong. Only other option is to make a sort of alphabet bubble function, but I was hoping the solution was already there somewhere.

carguy84

10:11 am on Apr 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not stick the array into a recordset if you want to sort (and not use bubble)?

Otherwise, you can use this function to bubble sort the array:

Sub SortArray(aTempArray)
Dim iTemp, jTemp, strTemp

For iTemp = 0 To UBound(aTempArray)
For jTemp = 0 To iTemp

If strComp(aTempArray(jTemp), aTempArray(iTemp)) > 0 Then
'Swap the array positions
strTemp = aTempArray(jTemp)
aTempArray(jTemp) = aTempArray(iTemp)
aTempArray(iTemp) = strTemp
End If

Next
Next
End Sub

But, if this is a frequently used action, I'd find a different solution, as it is a little taxing.

Chip-