1, requirements: VBScript the functional support of the array is relatively weak relative to other languages, but in the script application often use arrays, even array sorting, such as: traversing a directory of all the files, and then a rule to save to the array.
2, the implementation method: Since VBScript itself is not functional enough, you can invoke the functionality of the. NET Framework-related components (Mscoree.dll), specifically implemented as follows:
1> Write array sort functions (Parameters: Arrays):
Function asortarray (Array) dim i,oarraylist, ielement,temparray () ' CreateObject ( "System.Collections.ArrayList" ) that is called Mscoree.dll, is .net Related components of the framework set oarraylist = createobject ( " System.Collections.ArrayList " ) For iElement = 0 To UBound (Array) oarraylist.add array (ielement) Next ' Call object sorting method oArrayList.Sort redim Temparray (Oarraylist.count) for i=0 to oArrayList.Count-1 if oarraylist.item (i) <> "" Then temparray (i) = oarraylist.item (i) end if next asortarray=temparrayend function ' Note: Since oarraylist is an object, it does not make sense to do it directly as a return value, so it is necessary to re-process the Oarraylist object and store only its value. The array of the above sort results output is sorted from small to large, to get an array of results from large to small, change temparray (i) = oarraylist.item (i) to temparray ( Arraylist.count-1-i) = oarraylist.item (i) .
2> Verification Features:
Sub main Dim arrs,a,i Arrs=array (12,14,70,2,89,412,87,41,8,-7,60) A=asortarray (ARRS) for i=0 to UBound (a) If A (i) <> "then log. Message (A (i)) End If NextEnd Sub
Operation, the output is as follows:
650) this.width=650; "title=" QQ picture 20141103164643.png "Src=" http://s3.51cto.com/wyfs02/M01/4D/B0/ Wkiol1rxqy6yyrkqaaa-zzdwxo8852.jpg "alt=" Wkiol1rxqy6yyrkqaaa-zzdwxo8852.jpg "/>
This article is from the "Qytag (upspringing)" blog, so be sure to keep this source http://qytag.blog.51cto.com/6125308/1571324
VBScript script implements array sorting