Javascript question
Results 1 to 3 of 3

Thread: Javascript question

  1. #1
    Junior Member
    Join Date
    Jan 2003
    Posts
    10

    Javascript question

    Hello!

    I was wondering if anyone knows how to check for the end of file using Javascript and Active X.

    I want to perform a while loop using the condition "while not end-of-file". Unfortunately, EOF, eof, EOF(), eof()... do not work at all in Microsoft internet explorer 6.

    Here is part of my code:

    // This creates a new Active X Object in order to read in a file.
    // Refer to the new variable as "file"

    file = new ActiveXObject("Scripting.FileSystemObject");

    // Sets the variable "f" to equal the new open file contents

    f = file.OpenTextFile("c:\\wantlist.txt", 1);

    // This SHOULD keep looping until it reaches the end of the file
    // but doesn't!! It actually keeps looping without correctly checking the condition
    // until a javascript error pops up saying it's already reached the end of file when it
    // tries to read in the line.

    while(!line.EOF())
    {
    line = f.ReadLine();
    }

    Anyone know the correct syntax for checking an End-of-file for Javascript using Microsoft Internet Explorer 6 and up??

    I'd appreciate any help!

  2. #2
    Junior Member
    Join Date
    Mar 2003
    Posts
    16

    Re: Javascript question

    while(!line.EOF())
    {
    line = f.ReadLine();
    }
    You should be able to write the following:

    Code:
    while(line = f.ReadLine())
    {
    ...Do Stuff...
    }
    I'm not familiar with JavaScript, but this works in almost every other programming language out there. The read should return false when it hits the end of file.

  3. #3
    Junior Member
    Join Date
    Jan 2003
    Posts
    10

    Thumbs up Thanks!

    Thanks for the info Deltarra!

    I didn't know that such a check works in just about all languages. That'll come in handy!

    In addition, I figured out how to correctly check an end of file for this Active X "OpenTextFile" object:

    while(!f.AtEndOfStream)
    {

    }

    This works just fine for me.
    I appreciate your help Deltarra!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •