Excuse me for my last post, in spanish language. Is a mistake. Sorry.

You know if an array can order its elements?

Thanks!

Re: order array..... and sorry by Torgeir

Torgeir
Mon Mar 14 11:14:31 CST 2005

Tarllem wrote:

> Excuse me for my last post, in spanish language. Is a mistake. Sorry.
>
> You know if an array can order its elements?
Hi

ADO disconnected record set example as well as WSF file that uses
JScript array sort from a VBScript example here:

http://groups.google.co.uk/groups?selm=3E46392C.DE597514%40hydro.com


Alternatively, if you have only have up to a few hundred elements:

A QuickSort routine
http://groups.google.co.uk/groups?selm=3BE9E905.AFED21B4%40hydro.com

Bubble sort:
http://groups.google.co.uk/groups?selm=%23VMk1YAaBHA.1412%40tkmsftngp05


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: order array..... and sorry by Brian

Brian
Mon Mar 14 11:15:09 CST 2005

Tarllem wrote:
> Excuse me for my last post, in spanish language. Is a mistake. Sorry.
>
> You know if an array can order its elements?
>
> Thanks!

Hmmm, well, I think I guessed what you wanted, in any case. I'm not aware of any
built-in functions for sorting arrays, but the gurus here might know another
way. Maybe dictionary objects can do this?

Re: order array..... and sorry by McKirahan

McKirahan
Mon Mar 14 14:42:14 CST 2005

"Brian Wolven" <brian.wolven@domain.invalid> wrote in message
news:eLA2glLKFHA.2136@TK2MSFTNGP14.phx.gbl...
> Tarllem wrote:
> > Excuse me for my last post, in spanish language. Is a mistake. Sorry.
> >
> > You know if an array can order its elements?
> >
> > Thanks!
>
> Hmmm, well, I think I guessed what you wanted, in any case. I'm not aware
of any
> built-in functions for sorting arrays, but the gurus here might know
another
> way. Maybe dictionary objects can do this?

Sorting a Scripting Dictionary Populated with String Data
http://support.microsoft.com/support/kb/articles/Q246/0/67.ASP



Re: order array..... and sorry by Clay

Clay
Tue Mar 15 19:43:29 CST 2005

On Mon, 14 Mar 2005 12:15:09 -0500, Brian Wolven
<brian.wolven@domain.invalid> wrote:

>Tarllem wrote:
>> Excuse me for my last post, in spanish language. Is a mistake. Sorry.
>>
>> You know if an array can order its elements?
>>
>> Thanks!
>
>Hmmm, well, I think I guessed what you wanted, in any case. I'm not aware of any
>built-in functions for sorting arrays, but the gurus here might know another
>way. Maybe dictionary objects can do this?

Here's a technique that uses the command line sort program which is
very fast. I don't use ASP pages, but I doubt this will work in that
environment. The example array created contains characters that often
cause batch files to misbehave, but they don't have any effect on this
sort routine.

Dim sArray(9)

sArray(0) = "'$hell $ort!"
sArray(1) = "(l@y"
sArray(2) = "G,~_"
sArray(3) = "Z&r="
sArray(4) = "x%^v"
sArray(5) = "3>*6"
sArray(6) = "n<)v"
sArray(7) = "A 1."
sArray(8) = "t|u?"
sArray(9) = "s""k"

for Counter = 0 to 9
sList = sList & sArray(Counter) & VbCrLf
Next

Set oShell = Wscript.CreateObject("Wscript.Shell")
Set oExec = oShell.Exec ("%comspec% /c sort.exe")
oExec.StdIn.Write (sList & chr(26))

Counter = 0
Do while not oExec.StdOut.AtEndOfStream
sSort(Counter) = oExec.StdOut.ReadLine
wscript.echo sSort(Counter)
Counter = Counter + 1
Loop

I'm sure there is a better to handle the arrays in this routine. I
usually only work with multi-line strings such as what gets created
and put into the sList variable in this example. This technique will
also flash a CMD prompt if not using Cscript.

It may not be the most elegant routine, but it is handy for cscripts.
It also is handy to combine it with other command-line routines to get
output into files, such as.

Set oExec = shell.Exec ("%comspec% /c sort>File.txt&start File.txt")

Thanks,
Clay

Clay Calvert
CCalvert@Wanguru.com
Replace "W" with "L"

Re: order array..... and sorry by Clay

Clay
Sun Mar 20 20:52:18 CST 2005

On Tue, 15 Mar 2005 20:43:29 -0500, Clay Calvert
<ccalvert@Wanguru.com> wrote:

>On Mon, 14 Mar 2005 12:15:09 -0500, Brian Wolven
><brian.wolven@domain.invalid> wrote:
>
>>Tarllem wrote:
>>> Excuse me for my last post, in spanish language. Is a mistake. Sorry.
>>>
>>> You know if an array can order its elements?
>>>
>>> Thanks!
>>
>>Hmmm, well, I think I guessed what you wanted, in any case. I'm not aware of any
>>built-in functions for sorting arrays, but the gurus here might know another
>>way. Maybe dictionary objects can do this?
>
>Here's a technique that uses the command line sort program which is
>very fast. I don't use ASP pages, but I doubt this will work in that
>environment. The example array created contains characters that often
>cause batch files to misbehave, but they don't have any effect on this
>sort routine.
>
<snip>
>
>I'm sure there is a better to handle the arrays in this routine. I
>usually only work with multi-line strings such as what gets created
>and put into the sList variable in this example. This technique will
>also flash a CMD prompt if not using Cscript.

Well now I know a little more about vbscript arrays... here is a
better version. It is best to run this with cscript.

sArray = Split("The quick brown fox jumps over the lazy dog.")

For Each Item In sArray
sList = sList & Item & VbCrLf
Next

Set oShell = Wscript.CreateObject("Wscript.Shell")
Set oExec = oShell.Exec ("%comspec% /c sort.exe")
oExec.StdIn.Write (sList & chr(26))

N = 0
Do while not oExec.StdOut.AtEndOfStream
sArray(N) = oExec.StdOut.ReadLine
N = N + 1
Loop

For Each Item In sArray
wscript.echo Item
Next

Clay Calvert
CCalvert@Wanguru.com
Replace "W" with "L"