Click to See Complete Forum and Search --> : Parsing teststream file


Dashiva
October 1st, 2004, 03:39 AM
Alright, so i'm just some guy who doesn't know anything about this stuff.. but anyway, i'm writing this Jscript file to parse a text dump of a report we get here at work.

I load the text file..
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile(fileLocation, 1);

Then proceed to read each line in a loop, determining if I need what's in the line etc:
for (i=0; i<150; i)
{
line = f.ReadLine();
// Various code to parse the text file, and throw it in an excell spreadsheet
}
Alright, so my problem is that I can't come up with a method to figure out how many lines are in the text file. In the For loop I have it set to 150 for testing purposes, but for example if I have i<150 and the text file happens to be 10,000 lines, the script hangs.
I've tried to experiment with while (!f.AtEndOfStream) but can't seem to get it to work properly, it will just process one line, then quit...
Any ideas would be appreciated!
-Dasha

pawelg
October 1st, 2004, 05:12 AM
hi,
this code looks ok, check "while" statment, maybe You have ";" at the end

PawelG

Dashiva
October 1st, 2004, 05:44 AM
Alright,
so as a test I broke it down into the smallest form of this part of the script that would run: <HTML>
<HEAD>
<SCRIPT LANGUAGE="JScript">
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>

var f, fso, line;
var fileLocation = "c:\\test\\test.txt";

// Open text file for reading
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile(fileLocation, 1);

while (!f.AtEndOfStream)
{
line = f.ReadLine();
document.write(line + "<br>");
}

</SCRIPT>
</BODY>
</HTML>
And it seems to work OK, so there must be somthing else in my original code that's messing with it...

Dashiva
October 1st, 2004, 06:13 AM
Ok so I was an idiot and left an unassigned variable within the code that incrimented the for loop. Of course this made it come to a screeching halt.

Living proof that alcohol + programming do not mix. :D