Announcement

Collapse
No announcement yet.

how to code output to a file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to code output to a file

    What's wrong with the code below? This is just a bit so I can figure out to write to the file for each bar the EFS processes. As it is, it just rights for the last bar.


    var f = new File("test.txt");

    function preMain(){

    }

    function main(sTime, eTime){

    f.open("wt");
    f.writeln(close());
    f.close();

    return;
    }

  • #2
    Easy solution...

    You file parameters are set to "wt" - which overwrites the file each time...

    You want to set it to "at" - for appending...

    The easiest way to address this is as follows....

    create a function that controls the actions of your write file..

    PHP Code:
    function fcreatefile(vCreateTypevInfo)
    {
       if (
    vCreateType == "NEW") {
        if(!
    f.exists()) {  
          
    f.open("wt");
          
    f.writeln(vInfo);
          
    f.close();
        } else {
      
    ///   notice these two are the same - but you may need to do different things here.
          
    f.open("wt");
          
    f.writeln(vInfo);
          
    f.close();
        }
       }

       if (
    vCreateType == "ADD") {
        if(!
    f.exists()) {  
          
    f.open("at");
          
    f.writeln(vInfo);
          
    f.close();
        } else {
          
    f.open("wt");
          
    f.writeln(vInfo);
          
    f.close();
        }

       }



    The way you would call this function is simple....

    To create a NEW FILE...

    fcreatefile("NEW", close());

    To append to an existing file...

    fcreatefile("ADD", close());
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      oops - copy/paste error.

      Here is a correction to the code..

      PHP Code:
      function fcreatefile(vCreateTypevInfo)
      {
         if (
      vCreateType == "NEW") {
          if(!
      f.exists()) {  
            
      f.open("wt");
            
      f.writeln(vInfo);
            
      f.close();
          } else {
        
      ///   notice these two are the same - but you may need to do different things here.
            
      f.open("wt");
            
      f.writeln(vInfo);
            
      f.close();
          }
         }

         if (
      vCreateType == "ADD") {
          if(
      f.exists()) {  
            
      f.open("at");
            
      f.writeln(vInfo);
            
      f.close();
          } else {
            
      f.open("wt");
            
      f.writeln(vInfo);
            
      f.close();
          }

         }



      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        Brad, thank you. That did the trick. I have no idea what I'm doing but getting results kinda fun

        Comment

        Working...
        X