Announcement

Collapse
No announcement yet.

Array question

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

  • Array question

    Hi Guys...
    I've got an array of symbols
    var CurrencyValue = new Array("EUR A0-FX", "AUD A0-FX", "JPY A0-FX", "CHF A0-FX", "GBP A0-FX", "SEK A0-FX", "CAD A0-FX");

    and a delimited file containing "some" of those symbols, and these file contents change constantly.
    CHF A0-FX|B|68.166|100000.0|-131770.0|25739659|-100000|1.3135|S|80681.908
    JPY A0-FX|B|142.086|100000.0|-1.2044E7|25741257|-100000|120.05|S|80681.908


    I'm trying to read through the array and set a global value equal to something if, for that symbol, it finds an entry in the report.account file.... and if it does NOT find an entry, then to set the same global variable but with a different value. Problem is... say there are 2 items in the file, and its already iterated once through the file... it sets the global value of the previous element to the wrong value. I'm not a wizard with arrays by any stretch of the imagination...

    var CurrencyValue = new Array("EUR A0-FX", "AUD A0-FX", "JPY A0-FX", "CHF A0-FX", "GBP A0-FX", "SEK A0-FX", "CAD A0-FX");
    var fl = new File( "account.report" );
    if( fl.exists() && (!fn.exists())) {
    fl.open( "rt" );
    var line;
    while( !fl.eof() ) {
    line = fl.readln();
    if(line != null){
    var sline = line.split("|");
    for (x=0; x<7; x++) {
    nMyValue = CurrencyValue[x];
    debugPrintln("X Currency is " + CurrencyValue[x] + "\n");
    if(sline[0] == CurrencyValue[x] ){
    var symbolvar = sline[0]+"info";
    setGlobalValue(symbolvar,sline);
    debugPrintln("Global Value is " + symbolvar + " Val: " + getGlobalValue(symbolvar) + "\n");
    }
    if(sline[0] != CurrencyValue[x] ){
    var symbolvar = sline[1]+"info";
    setGlobalValue(symbolvar,sline);
    debugPrintln("Global Value is " + symbolvar + " Val: " + getGlobalValue(symbolvar) + "\n");
    }
    }
    }
    }
    fl.close();
    }

    any thoughts or ideas would be greatly appreciated.
    Chris

  • #2
    Hi Chris,

    two thoughts without getting into specifics. I would recommend comma delimiting the values in the file. That is because when you write an array back to the file, it is automatically comma delimited.

    The other is that when you split the line that is read from the file, every array element is is a text type, regardless of whether it was written as a number or not.

    There are several ways to recognize which values should be numbers versus which should be text, but you may already have a plan for this.

    Comment


    • #3
      Chris,

      After looking at further, I see you understand the text thing well, let me add...

      I suspect that when you are creating the array of symbols in this example, they may not be the same text values as is in the files. The best way to work this is to read in the file completely in your "do" loop. Then do all your queries. If you need to write anything back to the file, writeover everything in the file with all of the values, including any changes.

      Comment


      • #4
        Hi Chris,

        I went ahead and modified your efs such that it is self sufficient. What I mean is that I had the efs create the file that you were reading. Further, I put a number of debug statements in there to help me troubleshoot.

        I then read the file, closed it, typed the variables, looked for matches, then added another line of data, then wrote it over the file created in the beginning of the efs.

        I spent about two hours on this, I would goof up and the thing would lock up eSignal because I would make it go into an infinite loop.

        I hope this helps you work through the issue...



        PHP Code:
        var tmp = new Array();
        tmp[0] = new Array("CHF A0-FX","B","68.166","100000.0","-131770.0","25739659","-100000","1.3135","S","80681.908");
        tmp[1] = new Array("JPY A0-FX","B","142.086","100000.0","-1204400","25741257","-100000","120.05","S","80681.908");

        var 
        sFile = new File"account.report" ); 
        sFile.open"wt+" ); 
        for (var 
        i=0;i<tmp.length;i++){
            
        sFile.writeln(tmp[i]);
        }
        sFile.close(); 

        var 
        test = new Array();

        var 
        CurrencyValue = new Array("EUR A0-FX""AUD A0-FX""JPY A0-FX""CHF A0-FX""GBP A0-FX""SEK A0-FX""CAD A0-FX");
        debugPrintln("15: CurrencyValue = "+CurrencyValue+" CurrencyValue.length = "+CurrencyValue.length);
        var 
        fl = new File"account.report" ); 
        var 
        tmpLine;

        // let us check the file
        if(fl.exists()) { 
            
        fl.open"rt+" ); 
            var 
        line;
            var 
        0;
            while(!
        fl.eof())
            {
                
        tmpLine fl.readln();
                
        debugPrintln("27: tmpLine = "+tmpLine+" typeof(tmpLine) "+typeof(tmpLine));
                
                if (
        tmpLine !=null /* && tmpLine !=undefined */){
                    
        test[x++] = tmpLine;
                    
        debugPrintln("31: test["+(x-1)+"] = "+test[x-1]+" typeof(test[x-1]) "+typeof(test[x-1])+" test.length = "+test.length);
                }
            }
            
        debugPrintln("34: test["+(x-1)+"] = "+test[x-1]+" typeof(test[x-1]) "+typeof(test[x-1])+" test.length = "+test.length);
            
        fl.close(); 
        }

        x=0;
        // this types the variables in the array according to how you set it up in the function
        do
        {
            
        test[x] = Categorize(test[x]);
            
        x++;
        }
        while(
        x<test.length);
            
        //  now, let us check for matches
        for(var x=0;x<test.length;x++){
            
        for (var 
        i=0;i<CurrencyValue.length;i++)
            {
                
        debugPrintln("52: ... test[x][0]==CurrencyValue[i] "+(test[x][0]==CurrencyValue[i])+" CurrencyValue["+i+"] = "+CurrencyValue[i]);
                if(
        test[x][0]==CurrencyValue[i]){
                    
        debugPrintln("54: hey, this is a match, see.. test[x][0]==CurrencyValue[i] "+(test[x][0]==CurrencyValue[i])+" CurrencyValue["+i+"] = "+CurrencyValue[i]);
                }
            }
        }

        // let us say we changed a value like added a line
        test[test.length] = test[0];

        var 
        changedFlag true;

        if (
        changedFlagOverWriteFile(sFile,test);
            
        debugPrintln("66: hey, this efs is complete");

        // support functions support functions support functions support functions support functions 
        function OverWriteFile(a,b)
        {
            
        a.open"wt+" ); 
            for (var 
        i=0;i<b.length;i++){
                
        a.writeln(b[i]);
            }
            
        a.close(); 
        }

        function 
        Categorize(tmp)
        {
            
        debugPrintln("80: tmp = "+tmp+" typeof(tmp) = "+typeof(tmp));
            
        tmp tmp.split(",");
            
        tmp = new Array(tmp[0],tmp[1],tmp[2]*1,tmp[3]*1,tmp[4]*1,tmp[5]*1,tmp[6]*1,tmp[7]*1,tmp[8],tmp[9]*1);

            return 
        tmp;

        Comment


        • #5
          Hi Steve... thanks a bunch, have it all worked out now !

          Chris

          Comment

          Working...
          X