Announcement

Collapse
No announcement yet.

Retrieving FP Values

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

  • Retrieving FP Values

    I need to define the following array as a global array.

    var calcReturns = new Array(nPeriods);
    for (var i=0;i<nPeriods;i++) {calcReturns[i]=new Array(2)};

    But, nPeriods is defined in the FP array in preMain. I'm unsure how to retrieve this value so that I can use it when defining this array outside of main. I tried searching but couldn't come up with anything. Thanks.

  • #2
    Hi AssetHound,

    This will work for you. Since your example showed you wanted to set up a two dimensional array, I gave you three different techniques you can use. I then output them to the formula output window to show how each technique has their array element accessed and the actual data that each array element contains.

    I hope this helps.


    PHP Code:
    //Global Variables

    var bInit false;
    var 
    calcReturns1// variable defined in global scope, 
    var calcReturns2// variable defined in global scope, 
    var calcReturns3// variable defined in global scope, 
    var fpArray = new Array();

    function 
    preMain() {
     var 
    0;
     
    fpArray[x] = new FunctionParameter("nPeriods"FunctionParameter.NUMBER);
     
    withfpArray[x++] ) {
     
    setName("Length of array");
     
    setLowerLimit(2);
     
    setUpperLimit(30);
     
    setDefault(10);
     }
    }

    //== _Main processing function
    function main(nPeriods) {

     if(
    bInit == false){
     
    calcReturns1 = new Array();
     
    calcReturns2 = new Array();
     
    calcReturns3 = new Array();
     for (var 
    i=0;i<nPeriods;i++) {
      
    calcReturns1[i]=new Array(2);
      
    calcReturns2[i]= [0,0];
      
    calcReturns3[i]= {myName0:0,myName1:0};
     }
     
    bInit true;
     
    OutputArrays();
     }

    }

    function 
    OutputArrays(){
     
    debugPrintln("starting calcReturns1.length = "+calcReturns1.length);
     for (var 
    i=0;i<calcReturns1.length;i++) {
      
    debugPrintln("");
      
    debugPrintln("42: calcReturns1["+i+"][0] = "+calcReturns1[i][0]+"  calcReturns1["+i+"][1] = "+calcReturns1[i][1]);
      
    debugPrintln("43: calcReturns2["+i+"][0] = "+calcReturns2[i][0]+"  calcReturns2["+i+"][1] = "+calcReturns2[i][1]);
        
    debugPrintln("44: calcReturns3["+i+"].myName0 = "+calcReturns3[i].myName0+"  calcReturns3["+i+"].myName1 = "+calcReturns3[i].myName1);

     }
     
    debugPrintln("finished");

    Comment


    • #3
      This helps a lot. Thanks much.
      ----------------

      [QUOTE]Originally posted by stevehare2003
      [B]Hi AssetHound,

      This will work for you. Since your example showed you wanted to set up a two dimensional array, I gave you three different techniques you can use. I then output them to the formula output window to show how each technique has their array element accessed and the actual data that each array element contains.

      I hope this helps.

      Comment


      • #4
        Hi AH,

        You are most welcome, glad to hear it helped.

        Originally posted by AssetHound
        This helps a lot. Thanks much.
        FWIW, I had neglected to add the expected output to the formula output window in the previous post. Adding it here so the output can be seen without having to run it the efs ...



        PHP Code:
        starting calcReturns1.length 10

        42
        calcReturns1[0][0] = undefined  calcReturns1[0][1] = undefined
        43
        calcReturns2[0][0] = 0  calcReturns2[0][1] = 0
        44
        calcReturns3[0].myName0 0  calcReturns3[0].myName1 0

        42
        calcReturns1[1][0] = undefined  calcReturns1[1][1] = undefined
        43
        calcReturns2[1][0] = 0  calcReturns2[1][1] = 0
        44
        calcReturns3[1].myName0 0  calcReturns3[1].myName1 0

        42
        calcReturns1[2][0] = undefined  calcReturns1[2][1] = undefined
        43
        calcReturns2[2][0] = 0  calcReturns2[2][1] = 0
        44
        calcReturns3[2].myName0 0  calcReturns3[2].myName1 0

        42
        calcReturns1[3][0] = undefined  calcReturns1[3][1] = undefined
        43
        calcReturns2[3][0] = 0  calcReturns2[3][1] = 0
        44
        calcReturns3[3].myName0 0  calcReturns3[3].myName1 0

        42
        calcReturns1[4][0] = undefined  calcReturns1[4][1] = undefined
        43
        calcReturns2[4][0] = 0  calcReturns2[4][1] = 0
        44
        calcReturns3[4].myName0 0  calcReturns3[4].myName1 0

        42
        calcReturns1[5][0] = undefined  calcReturns1[5][1] = undefined
        43
        calcReturns2[5][0] = 0  calcReturns2[5][1] = 0
        44
        calcReturns3[5].myName0 0  calcReturns3[5].myName1 0

        42
        calcReturns1[6][0] = undefined  calcReturns1[6][1] = undefined
        43
        calcReturns2[6][0] = 0  calcReturns2[6][1] = 0
        44
        calcReturns3[6].myName0 0  calcReturns3[6].myName1 0

        42
        calcReturns1[7][0] = undefined  calcReturns1[7][1] = undefined
        43
        calcReturns2[7][0] = 0  calcReturns2[7][1] = 0
        44
        calcReturns3[7].myName0 0  calcReturns3[7].myName1 0

        42
        calcReturns1[8][0] = undefined  calcReturns1[8][1] = undefined
        43
        calcReturns2[8][0] = 0  calcReturns2[8][1] = 0
        44
        calcReturns3[8].myName0 0  calcReturns3[8].myName1 0

        42
        calcReturns1[9][0] = undefined  calcReturns1[9][1] = undefined
        43
        calcReturns2[9][0] = 0  calcReturns2[9][1] = 0
        44
        calcReturns3[9].myName0 0  calcReturns3[9].myName1 0
        finished 
        This output was from the C:\Program Files\eSignal\formulaoutput.log file

        Also enclosed is the efs which was uploaded to FileShare, with several additional tweaks to make it stand-alone...
        Attached Files

        Comment

        Working...
        X