Announcement

Collapse
No announcement yet.

EFS Include Function

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

  • EFS Include Function

    Does anyone have a way to include an external text file when creating a study with EFS (or make a call from a common location for text)? I don't want to have to retype the same text multiple times as I am writing the code, just make a call to a text file where I can write the code one time, and when I want to make changes to the code I will only have to make changes to that text in one place.

    Thanks

  • #2
    werosen
    As suggested in the Posting Guidelines link that Steve provided in his reply to the same question you asked in another thread post your code or a working example of what you are trying to accomplish and someone may be able to help
    Alex

    Comment


    • #3
      Example

      if( w = x)
      {
      var1 = abcdefg;
      var2 =hijklmno;
      "Continued typing with lots of other code"
      }

      if( w = y)
      {
      var1 = abcdefg;
      var2 =hijklmno;
      "Continued typing with lots of other code"
      }

      if( w = z)
      {
      var1 = abcdefg;
      var2 =hijklmno;
      "Continued typing with lots of other code"
      }

      Is there a function to call a text file, that contains the text:

      var1 = abcdefg
      var2 =hijklmno
      "Continued typing with lots of other code"

      such that I don't have to type all these lines over again in 28 places, and if I make a change in one of these lines, I only have to change it in one place. If you know ASP or PHP, this would be the equavalent to an 'include statement'.

      Comment


      • #4
        Try this..

        function main() {

        if( w = x)
        {
        MyCustomFunction();
        "Continued typing with lots of other code"
        }

        if( w = y)
        {
        MyCustomFunction();
        "Continued typing with lots of other code"
        }

        if( w = z)
        {
        MyCustomFunction();
        "Continued typing with lots of other code"
        }

        }


        function MyCustomFunction()
        {
        var1 = abcdefg;
        var2 =hijklmno;
        }

        You can create as many sub functions as you like. You can also read up on EFS2 and it's INCLUDE feature (libraries). But this should do the trick for you.

        B
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Actually, I just want to include the text, not calculate a value. My example was intended to illustrate the text I wanted to include, and not demonstrate a value I wanted to calculate.

          When I say text, I mean text in a literal sense, as in the characters I actually type on my keyboard. Therefore the question being:

          Is there a function to call a text file, such that I don't have to type all these lines over again in 28 places, and if I make a change in one of these lines, I only have to change it in one place. If you know ASP or PHP, this would be the equavalent to an 'include statement'.

          Comment


          • #6
            Sure...

            You can use this basic "file read" structure to create a function to load data from a text file...

            var f = new File("TestFolder/testReadWrite.txt");
            f.open("rt");

            var line;
            while(!f.eof()) {
            line = f.readln();
            debugPrintln("Line: [" + line + "]");
            }

            f.close();


            this example READS the TXT file from the formulaoutput directory.

            You should use "line.split(",")" to split the line into components..

            for example.. you read a line..

            date, time, identifier, text

            the split function breaks that line into 4 segments. Here is an example of a function that loads and matches an ID..

            PHP Code:
            function LoadDataFile(vID) {

            var 
            vDataFile "mydatafile.txt";
            var 
            line;
            var 
            IDFound false;


              
            debugPrintln("Attempting to load "+vDataFile );
            //if (v.exists()) {
              
            debugPrintln("Reading "+vDataFile );
            v.open("rt");
            if(
            v.open()) {
              
            debugPrintln(vDataFile +" Opened");
                while((!
            v.eof()) && (!IDFound )){
                 
            line v.readln();
                 if (
            line) {
                    
            PosCount line.split(",");
               
            //     debugPrintln(line);
                  
            if (PosCount[2] == vID) {
            //        debugPrintln(line);
                    
            YourDate PosCount[0];
                    
            YourTime PosCount[1];
                    
            YourText PosCount[3];
                    
            IDFound true;
                  }
                 }
                }

             
            debugPrintln(vDataFile +" Loaded  ");
            } else {
             
            debugPrintln("ERROR - "+vDataFile +" Not Found!");
            }
            null;

            Hope this helps..
            Brad Matheny
            eSignal Solution Provider since 2000

            Comment

            Working...
            X