Re: sorting arrays/dictionary
From: Richard Mueller [MVP] (rlmueller-NOSPAM_at_ameritech.NOSPAM.net)
Date: 03/25/04
- Next message: Bonj: "Re: high resolution timer in vbscript"
- Previous message: Yuri Niyazov: "Strange behavior when setting ACL on NTFS Folder"
- In reply to: McKirahan: "Re: sorting arrays/dictionary"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 25 Mar 2004 15:27:04 -0600
"McKirahan" <News@McKirahan.com> wrote in message
news:8tF8c.8047$JO3.14338@attbi_s04...
> "Andres M. Hidalgo" <ahidalgo@gulfins.com> wrote in message
> news:ugicFxoEEHA.1560@TK2MSFTNGP12.phx.gbl...
> > Is there any built-in way to sort an array or dictionary? Do I have to
> write
> > my own sorting routine?. Any code out there that I can use?.
> >
> > Andres
>
>
> Sorting a Scripting Dictionary Populated with String Data
> http://support.microsoft.com/support/kb/articles/Q246/0/67.ASP
>
Hi,
Or, if you would rather not code a bubble sort, you can use a "Disconnected
RecordSet". Below is based on a script in "Microsoft Windows 2000 Scripting
Guide", Chapter 17 (Creating Enterprise Scripts), pg 1102 (in my copy, the
text has an error, so watch it). This uses WMI to retrieve Service info from
a machine, populates a "Disconnected RecordSet", sorts by ServiceState, then
outputs:
Option Explicit
Dim objDataList, strComputer, objWMIService, colServices, objService
Const adVarChar = 200
Const MaxCharacters = 255
Set objDataList = CreateObject("ADODB.RecordSet")
objDataList.Fields.Append "ServiceName", adVarChar, MaxCharacters
objDataList.Fields.Append "ServiceState", adVarChar, MaxCharacters
objDataList.Open
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
("SELECT * FROM Win32_Service")
For Each objService In colServices
objDataList.AddNew
objDataList("ServiceName") = objService.Name
objDataList("ServiceState") = objService.State
objDataList.Update
Next
objDataList.Sort = "ServiceState"
objDataList.MoveFirst
Do Until objDataList.EOF
Wscript.Echo objDataList.Fields.Item("ServiceName") _
& vbTab & objDataList.Fields.Item("ServiceState")
objDataList.MoveNext
Loop
-- Richard Microsoft MVP Scripting and ADSI HilltopLab web site - http://www.rlmueller.net --
- Next message: Bonj: "Re: high resolution timer in vbscript"
- Previous message: Yuri Niyazov: "Strange behavior when setting ACL on NTFS Folder"
- In reply to: McKirahan: "Re: sorting arrays/dictionary"
- Messages sorted by: [ date ] [ thread ]