3 Replies Latest reply on Feb 23, 2013 11:35 PM by Trevorׅ

    Error String: 0 is read only

    Metrampaż

      I'm a totally newbie as far as scripting is concerned and that is why I need some help from you, Guys.

      I have a JSX script that is not working

       

      var wartosc = app.selection[0].contents;

      var i=0;

      Zamiana =wartosc;

      dl = wartosc.length;

      for (i=0; i<dl;i++)

      Zamiana[i]=wartosc[i]/4.15

      for (i=0; i<dl;i++)

      {

      Zamiana[i]=(Math.round(Zamiana[i]*100))/100

      Zamiana[i]=String(Zamiana[i])

      app.selection[0].cells[i].contents = Zamiana[i]

      }

       

      It should change selected (highlighted?) numbers (a separate indesign story) which is a national currency into Euro currency (4,15 is a current rate of exchange).

       

      Unfortunately i get an error saying:

      ---------------------------

      Adobe InDesign

      ---------------------------

      JavaScript Error!

       

      Error Number: 46

      Error String: 0 is read only

       

      Engine: main

      File: C:\Users\wZrokowiec\AppData\Roaming\Adobe\InDesign\Version 8.0\en_US\Scripts\Scripts Panel\euro.jsx

      Line: 6

      Source: Zamiana[i]=wartosc[i]/4.15

       

      Could anybody be so kind as to help me with it?

       

      Greetings to those who work on Saturdays :-)

       

      Metrampaż

        • 1. Re: Error String: 0 is read only
          Jump_Over Level 5

          Hi,

           

          Looks like this code asummes a table is selected.

          It replaces a numbers in every cell of table.

           

          Powo

          • 2. Re: Error String: 0 is read only
            Trevorׅ Adobe Community Professional

            Based on my very limited understanding of Polish and presuming that each selected table cell contains and only contains a single (multi digit) number then use this.

             

            I would use a grep function myself but as you call yourself a newbie I shan't include it

             

            var wartosc = app.selection[0].cells.everyItem().getElements(); // changed
            var i=0;
            Zamiana = []; // changed
            dl = wartosc.length;
            for (i=0; i<dl;i++) Zamiana[i]=wartosc[i].contents/4.15;  // changed
            for (i=0; i<dl;i++)
            {
                 Zamiana[i]=(Math.round(Zamiana[i]*100))/100;
                 Zamiana[i]=String(Zamiana[i]);
                 app.selection[0].cells[i].contents = Zamiana[i];
            }
            

            Regards to all those who work on Sundays

             

            Trevor

            • 3. Re: Error String: 0 is read only
              Trevorׅ Adobe Community Professional

              Looking at you code I see that you are looping through the cell twice for nothing.

               

              I would be better to just use something like this.

               

              var wartosc = app.selection[0].cells.everyItem().getElements();
              for (i=0; i<wartosc.length; i++) wartosc[i].contents = String ((Math.round(wartosc[i].contents*100/4.15))/100);
              

              Or if you want to store the resultant exchange values then use.

               

              var wartosc = app.selection[0].cells.everyItem().getElements();
              Zamiana = [];
              for (i=0; i<wartosc.length; i++) wartosc[i].contents = Zamiana[i] = (String ((Math.round(wartosc[i].contents*100/4.15))/100));