Issue With JavaScript and ClearScript
-
I'm learning to script an application with ClearScript. My program is a tabbed text editor and the idea is to have access to all the open files via a List. For scripting, the program opens a separate window (so that the script is not part of the scriptable collection). Results are written to a second textbox. And there is where I discovered the problem. At present I'm just having the Javascript display the "FilePath" property of each item in the collection. This works fine with this script:
parent.OutPut.Text="";
var i;
var y=0;
for (i = 0; i < parent.OpenFiles.Count; i++) {
y += 1
parent.OutPut.Text += y + " " + parent.OpenFiles[i].FilePath + "\r\n";}
parent.OutPut.Text += parent.OpenFiles.Count;I get the following correct result in the textbox: 1 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\WikipediaCrimeData_RawText.txt 2 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\conspiracytheory.html 3 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\USConsSearch.html 4 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\wordley.html 5 C:\Users\Alan\Documents\new 1.txt 6 C:\Users\Alan\Documents\10Comms.txt 7 C:\Users\Alan\Documents\testfile.txt 8 C:\Users\Alan\Documents\Transfer\From Toshiba\TestSpellChecker.txt 9 C:\Users\Alan\Documents\Projects\NetPadd2 Help Files\AdntlRsc.html 10 C:\Users\Alan\Documents\Projects\NetPadd2 Help Files\intro.html 11 C:\Users\Alan\Documents\ForLoop.js 12 untitled_2.txt 13 C:\Users\Alan\Documents\ForEach.js 13 ("13" is the number of items in the collection.) However, if I use this script:
parent.OutPut.Text="";
var x;
var i=0
for (x in parent.OpenFiles) {
i+=1
parent.OutPut.Text += i + " " + parent.OpenFiles[x].FilePath + "\r\n";}
parent.OutPut.Text += parent.OpenFiles.Count;I get the following result: 1 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\WikipediaCrimeData_RawText.txt 2 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\conspiracytheory.html 3 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\USConsSearch.html 4 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\wordley.html 5 C:\Users\Alan\Documents\new 1.txt 6 C:\Users\Alan\Documents\10Comms.txt 7 C:\Users\Alan\Documents\testfile.txt 8 C:\Users\Alan\Documents\Transfer\From Toshiba\TestSpellChecker.txt 9 C:\
-
I'm learning to script an application with ClearScript. My program is a tabbed text editor and the idea is to have access to all the open files via a List. For scripting, the program opens a separate window (so that the script is not part of the scriptable collection). Results are written to a second textbox. And there is where I discovered the problem. At present I'm just having the Javascript display the "FilePath" property of each item in the collection. This works fine with this script:
parent.OutPut.Text="";
var i;
var y=0;
for (i = 0; i < parent.OpenFiles.Count; i++) {
y += 1
parent.OutPut.Text += y + " " + parent.OpenFiles[i].FilePath + "\r\n";}
parent.OutPut.Text += parent.OpenFiles.Count;I get the following correct result in the textbox: 1 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\WikipediaCrimeData_RawText.txt 2 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\conspiracytheory.html 3 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\USConsSearch.html 4 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\wordley.html 5 C:\Users\Alan\Documents\new 1.txt 6 C:\Users\Alan\Documents\10Comms.txt 7 C:\Users\Alan\Documents\testfile.txt 8 C:\Users\Alan\Documents\Transfer\From Toshiba\TestSpellChecker.txt 9 C:\Users\Alan\Documents\Projects\NetPadd2 Help Files\AdntlRsc.html 10 C:\Users\Alan\Documents\Projects\NetPadd2 Help Files\intro.html 11 C:\Users\Alan\Documents\ForLoop.js 12 untitled_2.txt 13 C:\Users\Alan\Documents\ForEach.js 13 ("13" is the number of items in the collection.) However, if I use this script:
parent.OutPut.Text="";
var x;
var i=0
for (x in parent.OpenFiles) {
i+=1
parent.OutPut.Text += i + " " + parent.OpenFiles[x].FilePath + "\r\n";}
parent.OutPut.Text += parent.OpenFiles.Count;I get the following result: 1 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\WikipediaCrimeData_RawText.txt 2 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\conspiracytheory.html 3 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\USConsSearch.html 4 C:\Users\Alan\Documents\Transfer\From Toshiba\Projects\alanburkhart.com\wordley.html 5 C:\Users\Alan\Documents\new 1.txt 6 C:\Users\Alan\Documents\10Comms.txt 7 C:\Users\Alan\Documents\testfile.txt 8 C:\Users\Alan\Documents\Transfer\From Toshiba\TestSpellChecker.txt 9 C:\
I don't know anything about ClearScript, but in Javascript using
for(x in parent.OpenFiles) {
iterates over all the members of whatever
parent.OpenFiles
happens to be. That will includeparent.OpenFiles.Count
and any other attributes it has (attributes can be accessed usingparent.OpenFiles.Count
orparent['OpenFiles']['Count']
). Your lines of undefined values are members ofparent.OpenFiles
that don't have their own member calledFilePath
, and there must be 37 of them. Try usingparent.OutPut.Text += x + " " + parent.OpenFiles[x].FilePath + "\r\n";}
to see the attribute names instead of the numeric value you are assigning them.
-
I don't know anything about ClearScript, but in Javascript using
for(x in parent.OpenFiles) {
iterates over all the members of whatever
parent.OpenFiles
happens to be. That will includeparent.OpenFiles.Count
and any other attributes it has (attributes can be accessed usingparent.OpenFiles.Count
orparent['OpenFiles']['Count']
). Your lines of undefined values are members ofparent.OpenFiles
that don't have their own member calledFilePath
, and there must be 37 of them. Try usingparent.OutPut.Text += x + " " + parent.OpenFiles[x].FilePath + "\r\n";}
to see the attribute names instead of the numeric value you are assigning them.
Graham Breach wrote:
and any other attributes it has
I didn't realize that. Thank you. I was thinking in terms of the
For Each
loop in VB.Sometimes the true reward for completing a task is not the money, but instead the satisfaction of a job well done. But it's usually the money.