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

[amibroker] Re: JavaScript Problem with Array


  • Date: Tue, 08 Dec 2009 18:49:50 -0000
  • From: "bistrader" <bistrader@xxxxxxxxx>
  • Subject: [amibroker] Re: JavaScript Problem with Array

PureBytes Links

Trading Reference Links

Thanks.  Had to do some googling to understand "?" as used. Cool.  Thanks again.

--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> Bert,
> You were on the right track with the split function. The code below
> shows how you could iteratively open the second file, write the single
> selected element, close the file.
> I did that only because it looks to me like that was what you were
> trying for. If, in your real usage,  you are able to open/close the
> second file only once (i.e. before/after the loop) that would be far
> superior.
> var line;var fso, ts;var ForReading = 1, ForWriting = 2, ForAppending =
> 8;var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;var
> before = "C:\\Temp\\before.csv"var after = "C:\\Temp\\after.csv"
> fso = new ActiveXObject("Scripting.FileSystemObject");ts =
> fso.OpenTextFile(before, ForReading, false, TristateUseDefault);line =
> ts.ReadLine(); // First lineline = ts.ReadLine(); // Second
> linets.Close();
> myarray = line.split(",");count = myarray.length;
> for (i = 0; i < count; i++) {  access = (i == 0 ? ForWriting :
> ForAppending);  ts = fso.OpenTextFile(after, access, true,
> TristateUseDefault);  ts.Write("" + myarray[i] + (i < count - 1 ? "," :
> ""));  ts.Close();}
> Mike
> --- In amibroker@xxxxxxxxxxxxxxx, "bistrader" <bistrader@> wrote:
> >
> > Thanks Mike, but I want to be clear(er).  My plan is to expand this
> simple example to get me at individual values in the array.  In this
> case, the 10 values in the before.csv file provide information needed
> for 10 backtest runs.  So, when I modifiy the JavaSript to loop thru the
> 10 backtests, I need to get at one and only one of the array values in
> before.csv.  For example, when the JavaScript loop is on number 5, then
> I need to get at the 5th item in the second line of before.csv or what I
> was thinking would be myarray(5) of 1.  Know that you know this (and
> sorry for not being clear if I wasn't), does this change your reply?
> Thanks again!
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" sfclimbers@ wrote:
> > >
> > > You need to store the value that you have read, then write that
> value. Unless the lines in the file are very very long, a simple string
> will do.
> > >
> > > var line;
> > > var fso, ts;
> > >
> > > var ForReading = 1, ForWriting = 2, ForAppending = 8;
> > > var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
> > >
> > > var before = "C:\\Temp\\before.csv"
> > > var after = "C:\\Temp\\after.csv"
> > >
> > > fso = new ActiveXObject("Scripting.FileSystemObject");
> > > ts = fso.OpenTextFile(before, ForReading, false,
> TristateUseDefault);
> > >
> > > line = ts.ReadLine(); // First line
> > > line = ts.ReadLine(); // Second line
> > > ts.Close();
> > >
> > > ts = fso.OpenTextFile(after, ForWriting, true, TristateUseDefault);
> > > ts.WriteLine(line);
> > > ts.Close();
> > >
> > > Mike
> > >
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "bistrader" <bistrader@> wrote:
> > > >
> > > > Am trying to put together a simple JavaScript to eventually use
> with AmiBroker.  This JavaScript should ...
> > > >
> > > > 1. Start out with the before.csv file.
> > > > A,B,C,D,E,F,G,H,I,J
> > > > 5,4,3,2,1,10,9,7,6,6
> > > >
> > > > 2. Skip the first line and read the 10 numbers into an array.
> > > >
> > > > 3. Write this array to a new after.csv file.
> > > >
> > > > I am lost with all of my googling.  Here is what I have.  Help
> appreciated.
> > > >
> > > > var myarray = new Array();
> > > > var fso, ts, ts2, i;
> > > >
> > > > var ForReading = 1, ForWriting = 2, ForAppending = 8;
> > > > var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
> > > >
> > > > var before = "C:\\Amibroker\\Temp\\before.csv"
> > > > var after = "C:\\Amibroker\\Temp\\after.csv"
> > > >
> > > > fso = new ActiveXObject("Scripting.FileSystemObject");
> > > > //object.OpenTextFile(filename, iomode, create, format)
> > > > ts = fso.OpenTextFile(before, ForReading, false,
> TristateUseDefault);
> > > >
> > > > //ts.SkipLine();
> > > > //ts.ReadLine();
> > > > //myarray = ts.split(',');
> > > >
> > > > for (i = 1; i <= 10; i++)
> > > > {
> > > > ts.ReadLine();
> > > > //ts.ReadLine();
> > > > ts.ReadLine(myarray[i]);
> > > > }
> > > >
> > > > ts.Close();
> > > >
> > > >
> > > > ts2 = fso.OpenTextFile(after, ForWriting, true,
> TristateUseDefault);
> > > > ts2.Write(myarray + ',');
> > > > ts2.Close();
> > > > // The end
> > > >
> > >
> >
>




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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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

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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/