Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > ASP > ASP Forum > ASP Sorting a Dictionary Object ขอวิธีการ Sort Dictionary ของ ASP ด้วยครับ


 

[ASP] ASP Sorting a Dictionary Object ขอวิธีการ Sort Dictionary ของ ASP ด้วยครับ

 
Topic : 043007

Guest



ASP Sorting a Dictionary Object ขอวิธีการ Sort Dictionary ของ ASP ด้วยครับ



Tag : - - - -

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-05-18 14:32:08 By : Tinlau View : 2016 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (ASP)
01.Const dictKey  = 1
02.Const dictItem = 2
03. 
04.Function SortDictionary(objDict,intSort)
05.  ' declare our variables
06.  Dim strDict()
07.  Dim objKey
08.  Dim strKey,strItem
09.  Dim X,Y,Z
10. 
11.  ' get the dictionary count
12.  Z = objDict.Count
13. 
14.  ' we need more than one item to warrant sorting
15.  If Z > 1 Then
16.    ' create an array to store dictionary information
17.    ReDim strDict(Z,2)
18.    X = 0
19.    ' populate the string array
20.    For Each objKey In objDict
21.        strDict(X,dictKey)  = CStr(objKey)
22.        strDict(X,dictItem) = CStr(objDict(objKey))
23.        X = X + 1
24.    Next
25. 
26.    ' perform a a shell sort of the string array
27.    For X = 0 to (Z - 2)
28.      For Y = X to (Z - 1)
29.        If StrComp(strDict(X,intSort),strDict(Y,intSort),vbTextCompare) > 0 Then
30.            strKey  = strDict(X,dictKey)
31.            strItem = strDict(X,dictItem)
32.            strDict(X,dictKey)  = strDict(Y,dictKey)
33.            strDict(X,dictItem) = strDict(Y,dictItem)
34.            strDict(Y,dictKey)  = strKey
35.            strDict(Y,dictItem) = strItem
36.        End If
37.      Next
38.    Next
39. 
40.    ' erase the contents of the dictionary object
41.    objDict.RemoveAll
42. 
43.    ' repopulate the dictionary with the sorted information
44.    For X = 0 to (Z - 1)
45.      objDict.Add strDict(X,dictKey), strDict(X,dictItem)
46.    Next
47. 
48.  End If
49. 
50.End Function
51.                


A Working Example

Code (ASP)
01.<%@LANGUAGE="VBSCRIPT"%>
02.<% Option Explicit %>
03.<html>
04.<head><title>Dictionary Sorting</title></head>
05.<body>
06.<%
07. 
08.  Dim d, i
09. 
10.  Const dictKey  = 1
11.  Const dictItem = 2
12. 
13.  Set d = Server.CreateObject("Scripting.Dictionary")
14. 
15.  d.Add "3", "Delta"
16.  d.Add "1", "Foxtrot"
17.  d.Add "4", "Bravo"
18.  d.Add "2", "Echo"
19.  d.Add "6", "Alpha"
20.  d.Add "5", "Charlie"
21. 
22.  Response.Write "<p>Before Sorting:<br>"
23.  For Each i In d
24.    Response.Write i & "=" & d(i) & "<br>"
25.  Next
26. 
27.  Response.Write "<p>By Key:<br>"
28.  SortDictionary d,dictKey
29.  For Each i In d
30.    Response.Write i & "=" & d(i) & "<br>"
31.  Next
32. 
33.  Response.Write "<p>By Item:<br>"
34.  SortDictionary d,dictItem
35.  For Each i In d
36.    Response.Write d(i) & "=" & i & "<br>"
37.  Next
38.%>
39.</body>
40.</html>
41.<%
42.  Function SortDictionary(objDict,intSort)
43.    Dim strDict()
44.    Dim objKey
45.    Dim strKey,strItem
46.    Dim X,Y,Z
47.    Z = objDict.Count
48.    If Z > 1 Then
49.      ReDim strDict(Z,2)
50.      X = 0
51.      For Each objKey In objDict
52.          strDict(X,dictKey)  = CStr(objKey)
53.          strDict(X,dictItem) = CStr(objDict(objKey))
54.          X = X + 1
55.      Next
56.      For X = 0 to (Z - 2)
57.        For Y = X to (Z - 1)
58.          If StrComp(strDict(X,intSort),strDict(Y,intSort),vbTextCompare) > 0 Then
59.              strKey  = strDict(X,dictKey)
60.              strItem = strDict(X,dictItem)
61.              strDict(X,dictKey)  = strDict(Y,dictKey)
62.              strDict(X,dictItem) = strDict(Y,dictItem)
63.              strDict(Y,dictKey)  = strKey
64.              strDict(Y,dictItem) = strItem
65.          End If
66.        Next
67.      Next
68.      objDict.RemoveAll
69.      For X = 0 to (Z - 1)
70.        objDict.Add strDict(X,dictKey), strDict(X,dictItem)
71.      Next
72.    End If
73.  End Function
74.%>



http://support.microsoft.com/kb/246067
Date : 2011-05-13 10:10:29 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ASP Sorting a Dictionary Object ขอวิธีการ Sort Dictionary ของ ASP ด้วยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่