-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsorting-scripting-dictionary.asp
72 lines (51 loc) · 1.58 KB
/
sorting-scripting-dictionary.asp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<%
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 PrintDictionary(objDict, aTempArray)
Dim iTemp
For iTemp = 0 To UBound(aTempArray)
Response.Write(aTempArray(iTemp) & " - " & _
objDict.Item(aTempArray(iTemp)) & "<br>")
Next
End Sub
Sub PrintSortedDictionary(objDict)
Dim aTemp
Call BuildArray(objDict, aTemp) ' Build the array
Call SortArray(aTemp) ' Sort the array
Call PrintDictionary(objDict, aTemp) ' Print the dictionary using the array as an index
End Sub
Dim dObj, aTemp ' Create our dictionary variable name and the temporary array
Set dObj = Server.CreateObject("Scripting.Dictionary")
'-- Get some values
dObj.Add "Apple", "Value1"
dObj.Add "Orange", "Value2"
dObj.Add "Banana", "Value3"
dObj.Add "Grapefruit", "Value4"
dObj.Add "Avacado", "Value5"
Call PrintSortedDictionary(dObj)
Set dObj = Nothing ' Dereference the object
%>