Due to the requirements of needing .NET installed to use the arraysort ActiveX component, I came up with a workaround.
This function will accept either an array or a string, and will sort it. If the arraysort activex is available, it will use it for the array, but if it isn't it will use the DOS sort routine to perform the sort. kinda kludgy, but...
I was able to sort a 40,000 line (750KB) list in 0.53125 seconds with this, using the DOS sort routine.
A 4.4MB file containing our company's GAL (8,000 lines, each line around 600 characters long) was sorted in 0.7 seconds.
I think that this is an acceptable amount of overhead for a sort routine, don't you?
You can modify the sort command based on your particular OS, as some have different switches/arguments. This function has been tested on XP, 2003, and Windows NT 4.0.
Function fSort(oSortThisObject)
'This function will sort either a string or an array using an ActiveX sort routine, or
'if that is not available on the machine, a CLI SORT command.
'If an array, then it will return a sorted array.
'If a string, it will return a sorted string.
Dim sSortTemp, sSortCmd, oArrayList, iErr, iElement
Dim oFSO, oShell
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
Dim aVerText, aOS, VerLine, sOSString
sTmpFile1 = "c:\" & oFSO.GetTempName
oShell.Run "%comspec% /c ver > " & sTmpFile1,0,True
aVerText = Split(oFSO.OpenTextFile(sTmpFile1,1).ReadAll,VbCrLf)
oFSO.DeleteFile sTmpFile1, True
aOS = Array("Windows 95", "Windows 98", "Windows NT", "Windows 2000", "Windows XP", "Microsoft Windows [Version")
For Each VerLine In aVerText
For iElement = 0 To UBound(aOS)
If InStr(VerLine, aOS(iElement)) <> 0 Then
If aOS(iElement) = "Microsoft Windows [Version" Then
sOSString = "Windows 2003"
Else
sOSString = aOS(iElement)
End If
End If
Next
Next
'Insert commands for your particular OS here in a new case.
Select Case sOSString
Case "Windows NT"
sSortCmd = "%comspec% /c sort < "
Case Else
sSortCmd = "%comspec% /c sort "
End Select
sSortTemp = "c:\" & oFSO.GetTempName
If IsArray(oSortThisObject) Then
On Error Resume Next
Set oArrayList = CreateObject( "System.Collections.ArrayList" )
iErr = Err.Number
On Error GoTo 0
If iErr = 0 Then
For iElement = 0 To UBound(oSortThisObject)
oArrayList.Add oSortThisObject(iElement)
Next
oArrayList.Sort
For iElement = 0 To UBound(oSortThisObject)
oArrayDic.Add oArrayDic.Count,oArrayList(iElement)
Next
fSort = oArrayDic.Items
Else
oFSO.OpenTextFile(sSortTemp,8,True).WriteLine Join(oSortThisObject,VbCrLf)
oShell.Run sSortCmd & sSortTemp & " > c:\tmpshellfile.txt",0,True
fSort = Split(oFSO.OpenTextFile("c:\tmpshellfile.txt",1).ReadAll,VbCrLf)
oFSO.DeleteFile "c:\tmpshellfile.txt", True
oFSO.DeleteFile sSortTemp, True
End If
Else
oFSO.OpenTextFile(sSortTemp,8,True).WriteLine oSortThisObject
oShell.Run sSortCmd & sSortTemp & " > c:\tmpshellfile.txt",0,True
fSort = oFSO.OpenTextFile("c:\tmpshellfile.txt",1).ReadAll
oFSO.DeleteFile "c:\tmpshellfile.txt", True
oFSO.DeleteFile sSortTemp, True
End If
End Function
<message edited by DiGiTAL.SkReAM on Tuesday, October 10, 2006 2:26 AM>