Returning items sorted alphabetically.

Question:

At an application, a script is used to return all objects that are in a data folder. For example:


 For each obj in Application.GetObject(“Data”)
  MsgBox obj.name
 Next

Why are the items not returned in alphabetical order when executing this script?

Question:

This happens because when you use a for each loop, the system does not return data sorted alphabetically, but in the order that the objects were created.

To fix this problem, you must use the following script:


 Set data = Application.GetObject(“Data”)
 Set DataList = CreateObject(“System.Collections.ArrayList”)
 
 For each obj in data
  DataList.Add obj.name
 Next
 
 DataList.Sort()
 
 For Each obj1 in DataList
     MsgBox obj1
 Next

IMPORTANT: In order to execute this script, you must install Microsoft .NET Framework 3.5

Attachments:

SortedApp.zip

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *