🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #16629

Re: Converting prices and currencys

#16629
From: Shane Stanley
Date: Wed, 20 Aug 2003 23:26
49 lines
2757 bytes
Whoops. priceLength meant two different things. Try this version:



 
tell application "InDesign 2.0.2" 
	tell document 1 
		repeat with i from 1 to count of stories -- loop through stories 
			tell story i 
				set thePrices to (every word whose contents begins with "�") -- excludes decimal 
				set thePrices to reverse of thePrices -- we want to work from last to first 
				set thePricesIndex to index of (every word whose contents begins with "�") 
				if class of thePricesIndex is not list then 
					set thePricesIndex to {thePricesIndex} 
				end if 
				set thePricesIndex to reverse of thePricesIndex 
				repeat with j from 1 to count of thePrices 
					set decimalLength to 3 -- characters in decimal 
					set priceLength to length of (item j of thePrices) -- characters in price 
					try 
						-- get decimal 
						set theDecimal to (characters ((item j of thePricesIndex) + priceLength) thru ((item j of thePricesIndex) + priceLength + 2)) as real 
					on error -- chars weren't a number, so no decimal 
						set theDecimal to 0 
						set decimalLength to 0 
					end try 
					-- add decimal to price 
					set thePrice to ((text 2 thru -1 of (item j of thePrices)) as real) + theDecimal 
					-- convert price 
					set newPrice to (thePrice * 1.5) as real as text -- whatever factor is 		relevant		 
					-- trim to two decimal places 
					if character -2 of newPrice = "." then 
						set newPrice to newPrice & "0" 
					else 
						set pointOffset to offset of "." in newPrice 
						set newPrice to text 1 thru (pointOffset + 2) of newPrice 
					end if 
					-- insert new price 
					set contents of characters (get item j of thePricesIndex) thru ((item j of thePricesIndex) + priceLength + decimalLength - 1) to "$" & newPrice 
				end repeat 
			end tell 
		end repeat 
	end tell 
end tell 




Shane
Technical Details
Message-ID: <2cccf18e.6@webx.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!151.189.0.75.MISMATCH!newsfeed.arcor-online.net!newsfeed01.sul.t-online.de!t-online.de!webx
References: <2cccf18e.-1@webx.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f939a,6507d8367b744ba0
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-08-20 16:38:54 PST
From: "Shane Stanley" <sstanley@myriad-com.com.au>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!151.189.0.75.MISMATCH!newsfeed.arcor-online.net!newsfeed01.sul.t-online.de!t-online.de!webx
Newsgroups: adobe.scripting.indesign
Subject: Re: Converting prices and currencys
Message-ID: <2cccf18e.6@webx.la2eafNXanI>
Date: Wed, 20 Aug 2003 16:26:45 -0700
References: <2cccf18e.-1@webx.la2eafNXanI>
Lines: 54
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit