Re: Sorting Array's via VBS / JScript
From: Mr. Lee (Nospam_at_email.net)
Date: 09/22/04
- Next message: Al Dunbar [MS-MVP]: "Re: Finding a user's network login time"
- Previous message: Sergey P. Vazulia: "Cannot remove network printer!"
- In reply to: tlviewer: "Re: Sorting Array's via VBS / JScript"
- Next in thread: tlviewer: "Re: Sorting Array's via VBS / JScript"
- Reply: tlviewer: "Re: Sorting Array's via VBS / JScript"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 22 Sep 2004 10:36:19 -0400
I have over 74,000 records.
Thanks for the code.
I'll play with that and see how that works.
"tlviewer" <tlviewerSHRUB@yahoo.CHENEY.com> wrote in message
news:ORE1ar3nEHA.3988@tk2msftngp13.phx.gbl...
"Mr. Lee" <Nospam@email.net> wrote in message
news:utnk9wxnEHA.3896@TK2MSFTNGP15.phx.gbl...
> I have a large csv file that I'm loading into an array (vbscript) for some
> analysis.
>
> I need to sort the file/Array first so I can do proper reading.
> the file has become too large for me to sort in excel, and when I use the
> examples for vbscript sorting, it takes a huge amount of time.
>
> I've seen that jscript has a Sort Function but I'm not sure how I can get
> it
> to work in my vbscript.
>
> I'm doing something like this.
>
>
> set f = fso.opentextfile("mycsvfile.csv")
> MyArray = split(f.readall,vbcrlf)
>
> ' Now that I have the File in the array. I want to sort at this point. Can
> someone tell me what I need to do to be able to incorporate the jscript
> function into this?
>
> Thanks in advance.
> Mr. Lee
>
Its rare that a simple bubble sort in native VBS is not fast enough.
It takes 2000+ records before you will start to notice a difference.
Michael Harris has published a WSC quicksort scriptlet that
improves on a bubble sort.
http://www.aspobjects.com/process/code_repository/wsc/?file=Sort.wsc&subject=Array+Sorting+Routines
If you need even better speed, lately I tested a VB
wrapper around the CPP qsort, which will sort a variant
array of Bstr's in place.
I can sort a 10000 element array of random 23 char strings
in .0312 seconds ( P4 2.0 Ghz). This is up to 50 times
faster than a quicksort coded in native VBS.
It works great from VBS
http://4.11.211.97/cpp_qsort.zip (52 kB)
contains the VB DLL source, the CPP DLL source, and
some VBS samples.
' begin SortTest.vbs
''''''''''''''''''''''''''
option explicit
dim oArg
dim myIn, myhelpr
' extreme importance
' must first declare without parens
dim arTest
dim myAr, i,sOut, oMain, sTime
redim arTest(10000)
dim arOut
dim seed,t, oSort, sAscending , sDescending
seed = 4096
randomize seed
Rnd -1
' build test array of random 23 char strings
for i = 0 to Ubound(arTest)
arTest(i)= Cstr(RanPwd(23))
'sOut = sOut & arTest(i) & vbCrLf
next
wscript.echo vartype(arTest)
'wscript.echo Join( arTest, vbCrLf)
'set oSort = createobject("Sort.WSC")
set oSort = WScript.CreateObject("prjCSort.csort")
' in case of WSC
sAscending = "x1<x2"
sDescending = "x1>x2"
t = Csng(Timer)
arTest = oSort.qsort( arTest) ' .019 sec, 10k records
'arTest = oSort.HuthSort(arTest)
'oSort.QuickSortArray arTest, sAscending
sTime = FormatNumber(Csng(Timer)-t,9,-1)
wscript.echo "elapsed time=" & sTime & vbCrLf & Join( arTest, vbCrLf)
set oSort = nothing
' helper function
''''''''''''''''''''
' generate a random password from legal characters
Function RanPwd(nLen)
dim arrChar, nJ , spwd, schar, ran
arrChar = array("a","b","c","d","e","f","g","h", _
"i","j","k","l","m","n","o","p","q","r", _
"s","t","u","v","w","x","y","z", _
"A","B","C","D","E","F","G","H","I",_
"J","K","L","M","N","O","P","Q","R", _
"S","T","U","V","W","X","Y","Z", _
"-","_","%","#","|", _
"0","1","2","3","4","5","6","7","8","9")
if nLen = 0 then nLen = 10
spwd = ""
for nJ = 0 to nLen -1
ran = int(66 * Rnd) + 1
'wscript.echo ran
schar = arrChar(ran)
spwd = spwd & schar
next
RanPwd = spwd
end function
' end script
good luck,
tlviewer
- Next message: Al Dunbar [MS-MVP]: "Re: Finding a user's network login time"
- Previous message: Sergey P. Vazulia: "Cannot remove network printer!"
- In reply to: tlviewer: "Re: Sorting Array's via VBS / JScript"
- Next in thread: tlviewer: "Re: Sorting Array's via VBS / JScript"
- Reply: tlviewer: "Re: Sorting Array's via VBS / JScript"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|