4 Replies Latest reply on Jul 17, 2008 9:47 AM by (Lee_Fielding)

    [CS3 JS]  How does one ADD the contents of an Array together?

      Hello clever people...

      I'm wanting to add the contents of an array together - my old CS2 Script (that once worked) was:
      > myDaysSum = summieren(myDays);

      But now my machine tells me
      b 'summieren'
      is not recognised?

      Can anyone help?

      Thanks in advance,
      Lee
        • 1. Re: [CS3 JS]  How does one ADD the contents of an Array together?
          Level 1
          summerien must be a function in your old script. What have you done with it? It might well still work.

          Dave
          • 2. Re: [CS3 JS]  How does one ADD the contents of an Array together?
            Level 1
            Hello Dave,<br /><br />well... ummm - here's my scripting (I've twiddled' a little with it since I last wrote)<br />>if (app.documents.length != 0){<br><br />var myDoc = app.documents[0];<br />var myPath = myDoc.filePath;<br />var myDurationCharStyleName = "Duration"; <br />var myTotalDurationCharStyleName = "Duration Total";<br />//---------------------------------------------<br />app.findTextPreferences = null;<br />app.changeTextPreferences = null; <br />//---------------------------------------------<br />var myDaysSum = 0;<br />var myDaysTotal = 0;<br />app.findTextPreferences.appliedCharacterStyle = myDurationCharStyleName; <br />f = myDoc.findText();<br />mySum = CalculateTotal(f); <br />//---------------------------------------------<br />app.findTextPreferences = null;<br />app.changeTextPreferences = null; <br />}<br />function CalculateTotal(myData){<br />var mySum = 0;<br />var myCounter = 0;<br />for (myCounter = 0; myCounter<myData.length; myCounter++){<br />if (myData[myCounter].contents*1 + "" == myData[myCounter].contents){<br />mySum+=myData[myCounter].contents*1;<br />}<br />else {<br />myText += myData[myCounter].contents+ ", ";<br />}<br />}<br />return mySum;<br />}<br />app.findTextPreferences = null;<br />app.changeTextPreferences = null;     <br />app.findChangeTextOptions.includeMasterPages = true;<br />//<br />alert(mySum);<br />app.findTextPreferences.appliedCharacterStyle = myTotalDurationCharStyleName; <br />app.changeTextPreferences.changeTo = mySum; <br />myDoc.changeText();<br />//<br />app.findTextPreferences = null;<br />app.changeTextPreferences = null;     <br />app.findChangeTextOptions.includeMasterPages = true;<br /><br /> <br />But it still isn't working - giving me an error here:<br />> app.changeTextPreferences.changeTo = mySum;<br /><br />b Comment:<br><br />i Invalid value to set property 'changeTo'. Expected... but received 159<br /><br />Which is the value of training days = 159!!!<br /><br />I'm sure I'm doing things the hard way.... :(
            • 3. Re: [CS3 JS]  How does one ADD the contents of an Array together?
              Level 1
              changeTo needs a string. You're giving it a number.

              try:

              app.changeTextPreferences.changeTo = String(mySum);

              Dave