?
Solved

Sorting a  Dictionary Object alphabetically??

Posted on 2003-02-24
5
Medium Priority
?
469 Views
Last Modified: 2011-09-20
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
Comment
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
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Accepted Solution

by:
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

by:benlowry
ID: 8011024
Thanks!  Appreciate the quick response too!
0
 
LVL 2

Author Comment

by:benlowry
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)

  '-- Load the array
  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
    SortCart.add Prod, objDict(Prod)
  next

  objDict.RemoveAll
 
  Dim iTemp
  For iTemp = 0 To UBound(aTempArray)
    objDict.add aTempArray(iTemp), SortCart.Item(aTempArray(iTemp))
  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

by:benlowry
ID: 10333916
ahhahaha this was my question

i'm so tired :(
0
 
LVL 8

Expert Comment

by:ViRoy
ID: 12508151
ROFL
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question