Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 11, 2013, 04:15 AM   #1
scox
macrumors newbie
 
Join Date: Dec 2012
Location: Istanbul
Currency conversions in Word or Quark

So, I've had a little success with the Style Guide script folks here were so helpful with, and this has brought to light a new challenge currency conversion. This one has me completely stumped though, and after trying for two weeks and getting... well... nowhere, I appeal to ya'll for help.

For MS Word and Quark XPress, I've been trying to develop a script that will search a document for a user-defined currency, calculate a conversion of that currency (according to a user-defined exchange rate), and then include the new calculation in the text (in the user-defined target currency), such that it appears directly behind the original in parentheses.

Say I start with a paragraph like this:

The three richest states in Malaysia by GDP were Kuala Lumpur, with RM73.536 billion; Sarawak, RM49.48 billion; and Penang, RM46.744 billion.

I am trying to write an AppleScript that will prompt the user for the currency symbol (in this case, RM), request the target currency symbol ($), find and calculate each conversion automatically according to the user defined rate (RM1 = $0.328699), and include it in the text. If it could round the number to the nearest hundredth, that would be stellar.

The output I want, ideally, would look like this:

The three richest states in Malaysia by GDP were Kuala Lumpur, with RM73.536 billion ($24.17 billion); Sarawak, RM49.48 billion ($16.26 billion); and Penang, RM46.744 billion ($15.27 billion).

I understand that there's the possibility that the conversion would drop into the hundreds of millions, and that it is thus important for the conversion to be aware of the word following the currency. I don't even know where to begin tackling that part of the problem.

Basically, so far, I've managed only to prompt the user for the currencies and rates involved. That was the easy part, and since I've been stumped for so long, I felt it was time to ask around.

Any suggestions?
scox is offline   0 Reply With Quote
Old Jan 11, 2013, 12:54 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Does it have to be done directly in Word or Quark?

What options do those programs have for exporting and importing files? What formats?

When I think about the problem as given, I see two potentially separable problems:
1. Find and convert currencies in text.
2. Telling Word or Quark to do #1.

If #1 can be accomplished with doing #2, then it might be a simpler problem, or a wider range of possible solutions might be available.

For example, suppose Word can be told to export to a format like RTF. Since RTF is just a tagged text format, then any number of other tools that process text can be applied to the RTF, without the need for Word. After the RTF text has been transformed, Word can then be told to re-import the modified RTF.

A similar scenario applies for Quark, but I have no idea what Quark's import/export formats are, nor what fidelity issues there might be for a round-trip.


As to solving #1, the first thing you need to do is define what currencies to look for, and how those will be represented in text. Once that's been done in a specific way, we can evaluate what text-processing tools might be most suitable.

Be specific about currencies. Something that must recognize every currency in the world, in both localized and generalized forms, is a lot more complex (maybe even impossibly complex). Conversely, something that only needs to recognize the Malaysian ringgit as RM or MYR would be much simpler.
http://en.wikipedia.org/wiki/ISO_4217

Also specify any required context for currencies, such as localized assumptions. An example of a localized assumption is that $ in the US means the USD (US Dollar) currency. Australia's currency is also called "dollar", and the symbol is AU$, but there may be others, as well as an implicit assumption that in Australian publications an unadorned $ means Australian dollar (I'm guessing about the assumption, as I'm not Australian).


There are also some possibilities for making a service (the Services submenu under the app's self-named menu).

For a service, you would manually select a currency amount, choose the service, and the result would paste in the original amount plus a converted value. I think services can also be scripted, so that may be another approach after the conversion service has been created.

Services can be created in Automator, and then can use Automator actions as well as other scripting languages.
chown33 is online now   2 Reply With Quote
Old Jan 14, 2013, 07:49 AM   #3
scox
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Location: Istanbul
Hey, thanks a lot for the response.

You are totally right, I was trying to get Applescript to perform the conversion on a string. Oops. This weekend, I started trying to find a way to extract the currency figure as a string, change it to a number, and then perform the conversion.

So far, I have tried to do it directly in Quark. Exporting seems like a reasonable option, but I haven't yet figured out how to put the new figure back into the text, much less get it out.

Basically, I'm new enough at this that I didn't realize the real scale of the problem I was tackling. Oops. My outline of the component operations keeps growing:

- Search text for currency symbol
- read the numeric string behind the symbol (stopping when the value ends)
- save the string elsewhere (in the code, or in a list)
- convert the sting to a number
- calculate the conversion of the number
- save the conversion as a string
- insert the conversion string back into the text
- format it (put a $ or in front of it)
- move to the next incidence of the currency

I kind of makes my head spin.

As to your question about currencies, it is easier than I made it seem. It doesn't need to be taken from another source and the program doesn't need to recognize all currencies. Our publications are dedicated to a single country, so the writers send us most figures in the local currency, and the editors perform the conversion to either dollars or euros. As long as the key parameters can be set by the editor, I think the whole project is a bit simpler.

I'll play around with the services you mentioned. I was taken in by Applescript, initially, because my version of MS Word (2008) didn't support macros, and I wanted to design something for myself and my colleagues, who I later found out are all running various versions of Word from 2000 to 2011, on different Mac OSs. The company is, to put it politely, a bit technologically backwards. Applescript seemed like a good way to get a solution that could work for the whole department, despite the technological specifics.

In any event, thanks for the advice. I'll keep picking at the problem until I can get to the smallest bits of it, and I'll post any little successes I have. As it stands, it might be a project that is just far too out of my league, but it's been fun to play with.

Thanks again for the reply.
scox is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
B/W conversions kallisti Digital Photography 12 Jan 8, 2014 05:25 PM
The price conversions are outrageous mr.bee MacBook Pro 50 Nov 5, 2013 11:47 AM
Has anyone tried the color conversions for the iPhone 5? dr2391 iPhone 1 Dec 20, 2012 01:55 PM
iPhone 5 color conversions Krash11554 iPhone Accessories 2 Sep 27, 2012 09:23 PM
HELP!! 10.8.2 video conversions irnchriz Apple TV and Home Theater 6 Sep 24, 2012 02:42 PM

Forum Jump

All times are GMT -5. The time now is 01:47 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC