Herman, If you have Windows Scripting Host installed, available from MS here (if this works correctly):
http://tinyurl.com/62grg then you can run a shell Sort command using any parameters it supports. For example, to sort a file "c:\temp.csv" into "c:\temp2.csv", the code would look like this in JScript: var cmd = "Sort /+1 c:\\temp.csv /O c:\\temp2.csv"; var Shell = new ActiveXObject("WScript.Shell"); var rc = Shell.Run(cmd, 7, 0); or in VBScript: Dim WshShell, rc, cmd cmd = "Sort /+1 c:\temp.csv /O c:\temp2.csv" Set WshShell = CreateObject("WScript.Shell") rc = WshShell.Run(cmd, 7, False) Note that with JScript, the slashes in the path need to be doubled. The 7 in the Run command causes the script to run in a minimised window, so you don't see it. To sort by different columns, change the /+ parameter of the Sort command. I tried to get this working in an AFL function, but for some reason I can't get the AFL parameter passing variable to work at all, in either JScript or VBScript. Even if I just do this inside the script: AFL("str2") = AFL("str1") where both str variables are defined in AFL before the script, printing "str2" in AFL after the script always gives a blank string, no matter what "str1" is. Otherwise this could easily be added to a function, something like this (for JScript): EnableScript("JScript"); Function SortFile(inFile, outFile) { rcode = False; acmd = "Sort /+1 " + inFile + " /O " + outFile; <% var Shell = new ActiveXObject("WScript.Shell"); AFL("rcode") = Shell.Run(AFL("acmd"), 7, 0); %> return rcode; } To have the column as a parameter as well, pass it as an extra variable and use the NumToStr function to add it to the "acmd" string. GP
