PureBytes Links
Trading Reference Links
|
Bert,
I'm not a JScript/JavaScript expert. But, here's what I see:
1. Explicitly declaring your variables (i.e. using var keyword) is considered good practice. As such, you might want to consider using it consistently throughout your code. In your sample, you use it for some variables, but not for all (e.g. WLEmpty_Directory).
2. The code might be easier to read if you just declared the complete file path in a single variable, as opposed to concatenating it togeather from composite strings. Unless you need the composite parts for reuse later, I'd just collapse them into a single variable. Personal preference.
3. Same goes for the construction of your strings. No need to declare each segment as a variable if you don't plan to reuse them again later. Might be easier to read if you just concatenated it all at once
e.g.
var line1 = "I pick " + x + " of " + y + " for today.";
4. I believe that you are mis-using the call method of your function. Do not write:
VarAndQuotes.call(x,y);
Just move the declaration of the function to before its usage then simply call the same as any other function
VarAndQuotes(x,y);
If I understand correctly, your current usage is actually changing the 'this' object upon which the function is being called, which is probably not what you intended.
5. If you want to output quotes, you can probably escape them in the quoted string.
e.g.
var line3b = "\"My Winners\"";
6. I see no reason for calling AB.RefreshAll(); If for whatever reason you do need this call as a result of other (not shown) code, then I would at least move it out of this function since it is unrelated to the function's purpose.
7. Might want to check for successful return values from any of the functions that return them, and handle exceptions when value is not what was expected.
8. File usage looks fine to me.
Mike
--- In amibroker@xxxxxxxxxxxxxxx, "bistrader" <bistrader@xxx> wrote:
>
> Mike,
> I am having problems creating a txt file via JavaScript for AmiBroker use so I create the following simple example. I want the txt file to be exactly the following, but can not get the quotes to be included.
>
> I pick x of y for today.
> This is my final pick.
> These are "My Winners" for the day.
>
> Here, x and y are variables and My Winners is in quotes.
>
> Plus, I want to expand on this so would appreciate feedback on whether my approach to using a function, var, writeline and write, etc is a good way to approach writing what is needed to a file.
>
> Here is my example code and thanks
> **************************
>
> // Attempt to do the following.
> // 1. Set x to 5 and y to 8 for a function
> // 2. Create a file to write to called myoutput.txt
> // 3. Write the following to this file, where x is set to 5, y to 8.
> // I pick x of y for today.
> // This is my final pick.
> // These are "My Winners" for the day.
>
> // I am having problems writing My Winners in quotes.
>
> // ----------------------------------------------------------------------------
> // Create AmiBroker object and get Analysis object
> // ----------------------------------------------------------------------------
> var AB, AA;
>
> AB = new ActiveXObject("Broker.Application");
> AA = AB.Analysis;
>
> // ----------------------------------------------------------------------------
> // Set x = 5 and y = 8 for function
> // ----------------------------------------------------------------------------
> var x = 5;
> var y = 8;
>
> WLEmpty_Directory = "C:\\Amibroker\\Temp\\";
> WLEmpty_ExploreFileName = "myoutput.txt";
> WLEmpty_ExploreFile = WLEmpty_Directory + WLEmpty_ExploreFileName;
>
> VarAndQuotes.call(x,y);
>
> AA.ShowWindow(0);
>
> // ----------------------------------------------------------------------------
> // Function to create an txt where x and y change and with
> // some of the text in quotes
> // ----------------------------------------------------------------------------
> function VarAndQuotes(x1,y1)
> {
> var fso, f, ts;
> var x1, y1;
> var ForReading = 1, ForWriting = 2, ForAppending = 8;
> var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
>
> var line1a = "I pick ";// need to place 'x' after this
> var line1b = " of ";// need to place 'y' after this.
> var line1c = " for today.";
> var line2 = "This is my final pick.";
> var line3a = "These are ";
> var line3b = "My Winners";// need to somehow place in double quotes
> var line3c = "for the day.";// no carrage return after.
>
> fso = new ActiveXObject("Scripting.FileSystemObject");
> fso.CreateTextFile( WLEmpty_ExploreFile );
> f = fso.GetFile(WLEmpty_ExploreFile);
> ts = f.OpenAsTextStream(ForWriting, TristateUseDefault);
>
> ts.WriteLine ( line1a + x + line1b + y + line1c );
> ts.WriteLine ( line2 );
> ts.Write ( line3a + " + line3b + " + line3c );// DOES NOT WORK
> ts.Close( );
> AB.RefreshAll();
> }
>
>
>
> // Thanks for the help!
>
> // Bert
>
------------------------------------
**** 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/
|