Re: Passing String Variables to Visual Basic within Applescript???
Re: Passing String Variables to Visual Basic within Applescript???
- Subject: Re: Passing String Variables to Visual Basic within Applescript???
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 24 Jun 2001 12:32:51 -0700
On 6/24/01 12:07 PM, "Ian MacLachlan" <email@hidden> wrote:
>
Help,
>
>
I' m putting together a script (droplet) that takes user input
>
(old_string, new_string) and opens a series of Word Documents and makes
>
changes to the text using MS Word's replace command.
>
>
Question: How do I refer to the string variables captured in the
>
Applescript section when I initiate the Visual Basic section? The
>
relevant parts of the script follow. I'll attach the whole thing as
>
well.
>
Applescript that gets variables:
>
>
display dialog "What text would you would like to remove?" default
>
answer "Remove this text"
>
set the old_string to the text returned of the result
>
set old_string to ((old_string) as text)
You don't need this line. 'text returned' of display dialog is ALWAYS text.
>
>
display dialog "Any occurance of '" & old_string & "' will be replaced
>
with?" default answer "Replace with this text"
>
set the new_string to the text returned of the result
>
set new_string to ((new_string) as text)
Same. You don't need that line.
>
>
set the response_text to "Any text containing the string '" & the
>
old_string & "' will be replaced with '" & the new_string & "'."
>
display dialog response_text buttons {"OK"} default button 1
>
>
The section that opens Word and should make the repacements:
Before you do this, you need another handler to add escape characters (\")
for internal strings. I've also included the stuff you need in case you have
any carriage returns I your applescript strings (you don't this time, but
you might another time. Run each of your string variables (old_string,
new_string) through this handler.
on ProcessForVB(theString)
set finalString to ""
set num to (count paragraphs of theString)
repeat with i from 1 to num
set thePar to paragraph i of theString
set thePar to "\"" & thePar & "\""
set finalString to finalString & thePar
if i = num then
set finalString to finalString & return
else
set finalString to finalString & " & vbCr & "
end if
end repeat
return finalString
end ProcessForVB
--
Paul Berkowitz