Reply to topic  [ 4 posts ] 
variables and interpolated literals 
Author Message

Joined: 2007-03-28 07:30:34
Posts: 139
Getting back to learning the new macro language, I succeeded in writing a simple macro that even works. For reference, it's pasted below.

It simply builds a block of lines each starting with a number followed by a tab and newline character.
Following the line
$text = $prefix & $firstStep

I tried variations of
$text += "\t + \n"
$text & "\t + \n"
$text += "\t & \n"
and others to assemble the text added to the clipboard first. Some got complaints, but none succeeded in adding a tab and newline to the text added to the clipboard. (The pasted text was a single line.)

To add a tab or newline to text on the clipboard, do they have to be explicitly appended? Is there no way to assemble a string variable containing them that can then be appended to a clipboard?

Thank you.

Cliff Bender

***********
#NisusMacroProperty Name: _FlowChart Numbers

$message = 'What is the prefix?'
$prefix = Prompt Input $message, '', 'OK', 'S'

$message = 'What is the first number?'
$firstStep = Prompt Input $message, '', 'OK', '100'

$message = 'What is the last number?'
$lastStep = Prompt Input $message, '', 'OK', '10'

If $lastStep <= $firstStep
Die 'Sorry, the numbers are invalid.'
else
New Clipboard 'flowclip'
Switch to Clipboard 'flowclip'
Write Clipboard 'START'
Append to Clipboard "\n"
While $firstStep <= $lastStep
$text = $prefix & $firstStep
Append to Clipboard $text
Append to Clipboard "\t\n"
$firstStep = $firstStep + 1
end
Append to Clipboard "END \n"
Paste
end
Delete Clipboard 'flowclip'


2009-03-12 13:59:28
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
credneb wrote:
To add a tab or newline to text on the clipboard, do they have to be explicitly appended? Is there no way to assemble a string variable containing them that can then be appended to a clipboard?

There is a way, use the "&=" operator to append a string to an existing variable, eg:
Code:
$text = $prefix & $firstStep
$text &= "\t\n"

You could also do:
Code:
$text = "$prefix$firstStep\t\n"

Also, some unsolicited advice: you don't need to use a temporary clipboard to build your result. You could simply use a text variable, which is going to be faster:
Code:
$message = 'What is the prefix?'
$prefix = Prompt Input $message, '', 'OK', 'S'

$message = 'What is the first number?'
$firstStep = Prompt Input $message, '', 'OK', '100'

$message = 'What is the last number?'
$lastStep = Prompt Input $message, '', 'OK', '110'

If $lastStep <= $firstStep
   Die 'Sorry, the numbers are invalid.'
else
   $fullText = "START\n"
   While $firstStep <= $lastStep
      $fullText &= "$prefix$firstStep"
      $fullText &= "\t\n"
      $firstStep = $firstStep + 1
   end
   $fullText &= "END\n"
   Insert Text $fullText
end

Also, the "NisusMacroProperty Name" comment/directive isn't needed for macros authored by users. It's used internally by us to localized the display name of the macro for other languages, but unless you're also planning on updating all the NWP "lproj" folders to translate your macro title, the macro's file name should suffice.


2009-03-12 16:19:23
Profile WWW

Joined: 2007-03-28 07:30:34
Posts: 139
Thank you very much for the help, AND for the unsolicited advice. It helps the learning process and I like fast...
Your revised version is much more elegant, and as an example it answers several questions.

Thanks again.


2009-03-12 17:07:44
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Glad to help- happy macro writing!


2009-03-12 20:37:07
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software