Announcement

Collapse
No announcement yet.

File Object Problems

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • File Object Problems

    I have to report problems with the File object.

    In a text file, f.setPosition(number) doesn't work with either s = f1.read(number) or s = f1.readln(). In both cases, the setPosition does not function, and sometimes will move the pointer to the end of the file when only asked to move it a char or two.

    I am attaching a study that will write a short file and then attempt to read it. It is fully documented, so you can understand what I think I am observing.

    I'd appreciate any feedback.

    Thanks, Bob
    Attached Files

  • #2
    PHP Code:
    var f1 = new File("TestReadWrite_1.txt");

    function 
    preMain(){
        
    setPriceStudytrue );
        
        if(
    f1.exists()){//open the file and write 1 empty string to it.  This creates one line in the file which 
    your if statement is checking to see if the file exists (not the string that you have already declared). Since you have not created the file yet, it does not exist.

    Then on line 42 your subsequent file writes are only if(f1.exists() ){ Again the file does not exist, so there will be no writes. Remove the first if and just create the file. Personally, I do not check for this condition, as if you have already created the file, it already exists, so why check. I'm not trying to be flippant, I just have never had the problem, so I stopped checking. If I were going to check, I would check if the file did not exist and debugPrintln such that you are aware that there is something wrong.

    For example if(!(f1.exists()) ){
    debugPrintln("File Does not exist !!!!");
    return;
    }


    Regards,

    Comment


    • #3
      Steve,
      That is not the problem. I have no problem writting the file. It exists, and you can navigate to Program Files\eSignal\Formula Output and double click on the file icon and read it in NotePad.

      However, I will say that, (once and only once), I had a problem with the file not being found (didn't exits when checked for in preMain) but, magically, that problem didn't occur again....go figure.

      Anyway, the problem that needs to be resolved, probably by someone in development, is what I said in my first post. In the reading of the file, you cannot setPosition()...and then read from that position. Doesn't work with read() or readln()...play with my script and you will see what I am talking about

      Thanks anyway, Bob

      Comment


      • #4
        Well, I did take the time to download it an play with it. It did not create a file. It will only work if the file already exists. Sorry for trying to help, I'll let someone someone in development address this.

        Comment


        • #5
          Steve,
          All I can say is that it creates a file on my machine. If it doesn't do so on your machine, then I am at a loss to explain why. But it doesn't matter. That isn't the problem. There are a number of ways to write that file, any one of which will suffice.

          If you care to do so, comment out the problem if(...exists()) line and make it write a file for you. Then you will see the problem that I need help with...that we all need help with. It is not a file writting problem.


          Thanks, Bob

          Comment


          • #6
            Hello Bob,

            I have to agree with you. It doesn't seem like setPosition() is doing what is expected. What I've found is that setPosition(X) isn't doing anything unless X = 2, which will then set the pointer to the end of the file. I'll send some information about this to development and see if I can find out more about this. Here's the code example I used to test with.

            PHP Code:
            var f1 null;
            var 
            bPrint true;

            function 
            preMain(){
                
            setPriceStudytrue );
                
            setStudyTitle("setPosition test");
                
            setShowCursorLabel(false);
                
                if (
            f1 == nullf1 = new File("myFile.txt"); 
                
            f1.open("wt");
                
            f1.close();
            }

            debugClear();
            function 
            main(){
                
                if(
            bPrint == true){
                    if(
            f1.exists() ){
                        
            //debugPrintln("f1 exists");
                    
                        
            f1.open("at");
                        
            //f1.writeln("");
                        
            f1.writeln("123456789");
                        
            f1.writeln("123456789");
                        
            f1.writeln("123456789");
                        
            f1.close();
                    
                        
            //f1.open("rt");        
                        //f1.open("rt+");        
                        
            f1.open("at+");        
                        var 
            vLength f1.getLength();
                        
            debugPrintln("Length: " vLength);
                    
                        var 
            vPointerPos f1.getPosition();
                        
            debugPrintln("Before setPosition, Pointer: " vPointerPos);
                        
                        var 
            f1.readln();
                        
            f1.setPosition(22);
                        
            vPointerPos f1.getPosition();
                        
            debugPrintln("After setPosition, Pointer: " vPointerPos);
                    
                        
            f1.close();
                        
            bPrint false;
                    }
                }

                return;

            Jason K.
            Project Manager
            eSignal - an Interactive Data company

            EFS KnowledgeBase
            JavaScript for EFS Video Series
            EFS Beginner Tutorial Series
            EFS Glossary
            Custom EFS Development Policy

            New User Orientation

            Comment


            • #7
              Jason,

              It does not appear that setPosition() is working yet as of the 7.7 Release candidate. This feature would be nice to have functional.

              Regards,

              Comment


              • #8
                Hello Steve,

                I did report this a while back, but since it's not heavily used it may be a while before this one receives some attention from development. I will send another note on this to development again.
                Jason K.
                Project Manager
                eSignal - an Interactive Data company

                EFS KnowledgeBase
                JavaScript for EFS Video Series
                EFS Beginner Tutorial Series
                EFS Glossary
                Custom EFS Development Policy

                New User Orientation

                Comment

                Working...
                X