Solved

# Sorting a  Dictionary Object alphabetically??

Posted on 2003-02-24
Medium Priority
469 Views
Hi,

I'm in the final stages of an ecommerce site and I've noticed that when adding/removing from the order the products in the cart get shuffled around sometimes.

I've used a Dictionary Object to store the selected products in a session var.  If i can get the products sorted alphabetically before being displayed, this will eliminate the shuffling around.  Any suggestions?

Cheers,
Ben Lowry
0
Question by:benlowry
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3

LVL 2

Accepted Solution

rbagdonas earned 400 total points
ID: 8010872
The Dictionary object is simple to use, but features no sorting methods.

Check out this page for directions on how to setup the array to store the sorting stuff.

http://www.4guysfromrolla.com/webtech/062701-1.shtml
0

LVL 2

Author Comment

ID: 8011024
Thanks!  Appreciate the quick response too!
0

LVL 2

Author Comment

ID: 10333904
I have a sub I use to sort a dictionary object:

Call it using
SortOrder(dictionaryObject)

<%
'=========================================================
Sub BuildArray(objDict, aTempArray)
Dim nCount, strKey
nCount = 0

'-- Redim the array to the number of keys we need
Redim aTempArray(objDict.Count - 1)

For Each strKey In objDict.Keys

'-- Set the array element to the key
aTempArray(nCount) = strKey

'-- Increment the count
nCount = nCount + 1

Next
End Sub
'=======================================================
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
'=======================================================
Sub ReBuildArray(objDict, aTempArray)

Set SortCart = Server.CreateObject("Scripting.Dictionary")

for each Prod in objDict
next

objDict.RemoveAll

Dim iTemp
For iTemp = 0 To UBound(aTempArray)
Next

set SortCart = nothing

End Sub
'=======================================================
Sub SortOrder(objDict)
Dim aTemp
Call BuildArray(objDict, aTemp)
Call SortArray(aTemp)
Call ReBuildArray(objDict, aTemp)
End Sub
'=======================================================
%>
0

LVL 2

Author Comment

ID: 10333916
ahhahaha this was my question

i'm so tired :(
0

LVL 8

Expert Comment

ID: 12508151
ROFL
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
###### Suggested Courses
Course of the Month12 days, 10 hours left to enroll