🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #15301

JS: problem with changing numbers

#15301
From: Peter_Kahrel
Date: Thu, 11 Dec 2003 17:37
38 lines
2057 bytes
I've run into a strange problem that I can't solve. I want to be able to amend a series of numbers (line numbers), and I place these in a character style so I can easily find them. I thought I could use the following code to do that (all sorts of refinements omitted):

app.findPreferences = null;
app.findPreferences.appliedCharacterStyle = "Counter";
app.changePreferences.changeText = ""
f = app.activeDocument.search( undefined, false, false, undefined );
for( i = 0 ; i < f.length ; i++)
   {
   x = parseInt( f[i].contents );
   x++;
   f[i].contents = x.toString();
   }

This works well as long as all numbers are greater than or smaller than 10. But using this code to increment (or decrement) the range 8-12, for instance, with both single-digit and double-digit numbers, results in odd behaviour, presumably because the debugger shows that single-digit numbers are returned as objects of type Character, but double-digit numbers as objects of type TextStyleRange. Here are some results (first line is the original, second line is the first run, third line, second run, etc.):

Incrementing:

6 7 8 9
7 8 9 10
8 9 10 aN0
9 10 aN0 NN0
10 aN0 NN0 NN0
11 NaN NaN NaN

Decrementing

11 12 13 14
10 11 12 13
9 10 12 12
8 9 11 12
7 8 10 11
6 7 9 10
5 6 8 9

Both incrementing and decrementing give wrong results, but incrementing seems to be worse. Am I doing anything avoidably stupid? And can it be corrected?

Thanks,
Peter
Technical Details
Message-ID: <2ccee0cb.-1@webx.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webx

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,2ed4b74287ad5cda,start
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-12-11 09:38:29 PST
From: Peter_Kahrel@adobeforums.com
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webx
Newsgroups: adobe.scripting.indesign
Subject: JS: problem with changing numbers
Message-ID: <2ccee0cb.-1@webx.la2eafNXanI>
Date: Thu, 11 Dec 2003 09:37:00 -0800
Lines: 50
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit