3 Replies Latest reply on May 14, 2008 2:30 AM by (Aaron_Andrade)

    NaN on the run (add cell contents) [CS3, JS]

    Level 1
      Hello.

      This is my first attempt at javascripting ID, though I've done some amount of Applescripting.

      The intent of this script is to add the contents of the table cells that a user has selected.
      I can't figure out why this keeps returning 'NaN' (not a number) after I have told it to ignore any 'NaN' contents (and exclude them from the running total).

      -=-=-=-=-=-=-=-=-=-=-=-=-=-=-

      var theTotal=0;

      //If the selection is at least one table cell...
      if (app.selection[0].constructor.name == "Cell")
      {
      //count cells in selection
      var cellCount=(app.selection[0].cells.count(0));
      //repeat with count from 1 to count of cells
      for (a=0; a<=cellCount; a++)
      {

      //get contents of first selected cell in the loop
      cellVal=(app.selection[0].contents[a]);
      //convert string to # via parseFloat command
      cellValInteger=parseFloat(cellVal);
      if (cellValInteger!="NaN") //NaN = not a number
      {
      //set the variable to the sum of each cell value
      theTotal+=cellValInteger;}

      else{
      alert("Please fully select at least one table cell and try again.");
      }
      }
      }