Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

VBScript script implements array sorting

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

1, requirements: VBScript on the array function support is relatively weak compared to other languages, however, in the script to often use the array, and even array sorting, such as: traversing a directory of all files, and according to a certain rule saved to the array in turn.

2. Implementation method: since the function of VBScript itself is not enough, you can call the function of .NET Framework-related components (mscoree.dll) as follows:

1 > write an array sort function (parameter: array):

Function aSortArray (Array) Dim I CreateObject ArrayList, iElement,tempArray () 'ArrayList ("System.Collections.ArrayList") is called mscoree.dll. Is the related component of .NET Framework Set oArrayList = CreateObject ("System.Collections.ArrayList") For iElement = 0 To UBound (Array) oArrayList.Add Array (iElement) Next 'call the object's sorting method oArrayList.Sort redim tempArray (oArrayList.count) for item0 to oArrayList.Count-1 If oArrayList.item (I) "Then tempArray (I) = oArrayList.item (I) End If Next aSortArray=tempArrayEnd Function 'description: because oArrayList is an object It doesn't make much sense to use it directly as a return value, so you need to reprocess the oArrayList object and just store its value.' The array of the output of the above sorting results is sorted from small to large. To get the array of results from large to small, change tempArray (I) = oArrayList.item (I) to tempArray (ArrayList.Count-1-i) = oArrayList.item (I).

2 > Verification function:

Sub main Dim arrs,a,i arrs=Array (arrs) for item0 to UBound (a) If a (I) "Then log.Message (a (I))"

Run, and the output is as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report