The author found that the collection can be sorted by the collection, and it is much faster than the sputum method. The following is a complete function code that demonstrates how to perform an ascending or descending order of arrays.
Option Explicitdim X (100) AS Doubledim y (100) AS STRINGPRIVATE SUB Command1_Click () 'Demo Digital Sort DIM A (100) As Double, Z (100) AS String, I as Longfor I = 0 to 100A (i) = x (i) 'Copy array z (i) = CSTR (x (i))' Translate into a string array nextmsgbox join (z, ","), 64, "original array" display original order
NumBersort X, "UP" for i = 0 to 100Z (i) = CSTR (x (i)) 'Translated into a string array nextmsgbox Join (Z, ","), 64, "Sort by Digital Ascending]"' Show sort results
NumBersort a, "Down" for i = 0 to 100Z (i) = CSTR (A (i)) 'translates to a string array nextmsgbox join (z, ","), 64, "Sort by Digital Descending]' Show sort results
End subsub number (byref a () as double, OPTIONAL SORT AS STRING = "UP") 'Digital Sort DIM MIN AS Long, Max As Long, Num As Long, Temp As Long, All AS, AS LONG New Collection, Steps as longmin = lbound (a) max = Ubound (a) all.add a (min) steps = 1for Num = min 1 to maxlast = all.countif A (NUM)
First = 1do while last> first 1 'Reduces the number of cycles in the loop = (Last first) / 2IF A (NUM)> CDBL (all (temp)) TEMPELST = TempelselaSt = TempsTeps = Steps 1END iFloopall.Add A (NUM), before: = last 'adds to the specified index
Nextnum: steps = steps 1Nextfor Num = min to maxif sort = "UP" or sort = "UP" THEN A (NUM) = CDBL (All (Num - min 1)): Steps = Steps 1 'Ascending IF Sort = "Down" or sort = "down" THEN A (NUM) = CDBL (all (max - num 1)): Steps = steps 1 'Descendment nextmsgbox "This array has passed" & Steps & "Step Implementation" & IIF (Sort = "UP" or sort = "UP", "Ascending", "Descending") & "Sort!", 64, "Information" Set All = Nothingend Subsub Stringsort (Byref A () AS String, Optional Sort As String = "UP") 'string Sort DIM MIN AS Long, Max As Long, Num As Long, First As Long, Last As New Collection, Steps as Longmin = LBound (a) max = Ubound (a) all.add a (min) steps = 1for Num = min 1 to max
First = 1LAST = All.countif A (NUM)
Do WHILE LAST> FIRST 1 'Using Do Cycle Reduces Temp = (Last First) / 2IF A (Num)> All (Temp) THENFIRST = TempelselaASt = Tempsteps = Steps 1END ifloopall.add A (Num), Before : = Last 'Add to the specified index
Nextnum: steps = steps 1NEXTFOR NUM = min to maxif sort = "UP" or sort = "UP" THEN A (NUM) = All (Num - min 1): Steps = Steps 1 'Ascending IF Sort = "Down "Or sort =" Down "THEN A (NUM) = All (Max - Num 1): Steps = Steps 1 'Descendment nextmsgbox" This array has passed "& Steps &" step implementation "& IIF (sort =" UP "Or sort =" UP "," Sorts "," Descending ") &" Sort! ", 64," Information "set all = nothingend subsprivate subs sorting DIM Z (100) AS String, i As long 'replication array for i = 0 to 100Z (i) = y (i) Next
Msgbox Join (Y, ","), 64, "Original array" "Shows the original order
Stringsort Y, "UP" msgbox join (y, ","), 64, "Sequencing after String Squares" 'display Sampling Results
Stringsort Z, "Down" MSGBOX JOIN (Z, ","), 64, "Sort by Stroke Descending Sort Outue" 'display Sampling Result End Sub
PRIVATE SUB Command3_Click () 'Sort Meter Dim A (3000) AS String, I as Long, StartTime As Long, EndTime As Longfor I = 0 to 3000A (i) = CHR (INT * 26) 65) & chr ( INT (RND * 26) 65) & chr (INT * 26) 65) & chr (int (RND * 26) 65) & chr (int (RND * 26) 65) & chr (int RND * 26) 65) 'Generate Random 6 Character string NextStartTime = Timer' Timing Stringsort Alendtime = Timer 'Timing End MsgBox "Sorting Co-consumption" & EndTime - StartTime & "Second!" End Sub
Private Sub Form_Load () Randomizedim i as longfor i = 0 to 100X (i) = Format (RND * 1000, "0.00") Y (i) = chr (int (RND * 26) 65) & chr (INT) * 26) 65) & chr (int (RND * 26) 65) Nextend Sub