5 Replies Latest reply on Apr 21, 2010 12:36 PM by gkaiseril

    Array Advice

    mudz78

      Hi,

       

      I have been trying to come to grips with handling and Array in Adobe. Here is some test code I have been trying to get to work. What am I doing wrong?

       

      var raceArray = new Array(24);
      var splitArray = new Array(24,52);
      raceArray[0] = "1,0,2";

       

      parseOptions(raceArray[0]);

       

      getField("calc_Special").value = (splitArray[0,0] + splitArray[0,1] + splitArray[0,2]);

       


      function parseOptions(inputOptionsString){
      var splitArray = inputOptionsString.split(",");
      }

       

      Message was edited by: mudz78

        • 1. Re: Array Advice
          mudz78 Level 1

          Does this look better?

           

          var raceArray = new Array(24);
          var splitArray = new Array(3);
          raceArray[0] = "Cricket,Bowling";

           

          parseOptions(raceArray[0]);

           

          getField("calc_Special").value = (splitArray[1]);

           


          function parseOptions(inputOptionsString){
          splitArray = inputOptionsString.split(",");
          }

          • 2. Re: Array Advice
            try67 MVP & Adobe Community Professional

            Which kind of advice are you looking for? What is not working like you

            expect it to work?

            1 person found this helpful
            • 3. Re: Array Advice
              mudz78 Level 1

              I was basically trying to take a series of delimited strings and pass  them into an array. Not being familiar with the split function I was  having a few syntax challenges.

               

              My hope was to dump all  the strings into the (same) new "split" array. From there I could parse  the split array and pull out the values (based on user comboBox  selection) I needed using a unique name contained at the start of each  string. Couldn't get it working. Had problems getting all the split  strings into one array (could only do one string at a  time).

               

              What  I ended up doing was taking the user comboBox selection (unique and  correspoding to an unique string) and searching for a substring in the  original strings. Once I knew which string I needed, i would split it,  pull out my values and populate my form. Hey presto!

               

              Here's what I did:

               

               

              var  race = getField("combo_Race").value;

              var raceArray = new  Array(24);

              var  splitArray = new Array(51);

               

              raceArray[0]  ="Name1#String1#String2#...#String51";

              raceArray[1]  ="Name2#String1#String2#...#String51";

              ...

              raceArray[24]  ="Name24#String1#String2#...#String51;

               

              var i = 0;

              var   status = true;

               

              while(status){

                    if(race==(raceArray[i].substring(0,raceArray[i].indexOf("#")))){

                        parseOptions(raceArray[i]);

                       status = false;

                        populateForm(i);

                  }else{

                      ++i;

                  }

              }

               

              function  parseOptions(inputOptionsString){

                   splitArray =  inputOptionsString.split("#");

              }

               

              function  populateForm(arrayBlock){

                   getField("field1").value =  (splitArray[arrayBlock,1]);

                   getField("field2").value =  (splitArray[arrayBlock,2]);

                 ...

                   getField("field52").value = (splitArray[arrayBlock,52]);

               

              }

               

              It  works, but I am a noob and always open to suggestions.

               

              Regards.

              • 4. Re: Array Advice
                gkaiseril MVP & Adobe Community Professional

                You might want to read or look at the Core JavaScript 1.5 Reference to learn about the array object and the split method.

                 

                // define an array with 7 rows
                var raceArray = new Array(7);
                // load some data into the array
                raceArray[0] = "Row 1,0,0,1";
                raceArray[1] = "Row 2,0,1,0";
                raceArray[2] = "Row 3,0,1,1";
                raceArray[3] = "Row 4,1,0,0";
                raceArray[4] = "Row 5,1,0,1";
                raceArray[5] = "Row 6,1,1,0";
                raceArray[6] = "Row 7,1,1,1";
                // let us look at some properties of the array
                console.show();
                console.println('raceArray:');
                var toRaceArray = typeof raceArray;
                console.println('typeof raceArray: '  + toRaceArray)
                var lRaceArray = raceArray.length;
                console.println('length of raceArray: ' + lRaceArray)
                console.println('Elements of array:');
                // display elements of array
                for(i = 0; i < raceArray.length; i++) {
                console.println(i + ': ' + raceArray[i]);
                }
                console.println('');
                // look at one element of the array
                var nIndex = 5
                console.println('element: ' + nIndex);
                var sElement = raceArray[nIndex];
                console.println('typeof element: ' + (typeof sElement) );
                console.println('length of element: ' + sElement.length);
                console.println('value of element: ' + sElement);

                // make element into an array splitting at the coma
                var aElement = sElement.split(",");
                // element array properties
                console.println('typeof element array: ' + (typeof aElement) );
                console.println('length of element array: ' + aElement.length);
                // display elements of element array
                for(j = 0; j < aElement.length; j++) {
                console.println(j +': ' + aElement[j]);
                }

                • 5. Re: Array Advice
                  gkaiseril MVP & Adobe Community Professional

                  Or a different way to initialize the race array:

                   

                  // define an array with 7 rows
                  var raceArray = new Array(
                  ["Row 1", "0", "0", "1"],
                  ["Row 2", "0", "1", "0"],
                  ["Row 3", "0", "1", "1"],
                  ["Row 4", "1", "0", "0"],
                  ["Row 5", "1", "0", "1"],
                  ["Row 6", "1", "1", "0"],
                  ["Row 7", "1", "1", "1"] )
                  // llet us look at some properites of the array
                  console.show();
                  console.println('raceArray:');
                  var toRaceArray = typeof raceArray;
                  console.println('typeof raceArray: '  + toRaceArray)
                  var lRaceArray = raceArray.length;
                  console.println('length of raceArray: ' + lRaceArray)
                  console.println('Elements of array:');
                  // display elements of array
                  for(i = 0; i < raceArray.length; i++) {
                  console.println(i + ': ' + raceArray[i]);
                  }
                  console.println('');
                  // look at one element of the array
                  var nIndex = 5
                  console.println('element: ' + nIndex);
                  var aElement = raceArray[nIndex];
                  console.println('typeof element: ' + (typeof sElement) );
                  console.println('length of element: ' + sElement.length);
                  console.println('value of element: ' + sElement);

                  // element array properties
                  console.println('typeof element array: ' + (typeof aElement) );
                  console.println('length of element array: ' + aElement.length);
                  // display elements of element array
                  for(j = 0; j < aElement.length; j++) {
                  console.println(j +': ' + aElement[j]);
                  }