[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: How to sort lines in a file



PureBytes Links

Trading Reference Links

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



------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/