Home > Domino Tips > Developer > Formula > Paste templated text into Lotus Designer
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

FORMULA

Paste templated text into Lotus Designer


Shane Hollis
05.17.2005
Rating: -2.63- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


View member feedback to this tip.

NOTE -- After receiving feedback from several members of the SearchDomino community suggesting that a piece of code was missing from the tip below, the author of the tip sent us an update, which appears as the third item in the Member Feedback section of the tip. The author was using a compiled program called from this code and forgot to update the document. The author apologizes for any inconvenience this may have caused. (Posted June 6, 2005)

As a coder I get sick of having to write the same code over and over and over again. Sure, I can make script libraries and copy and paste templated code, but all that window changing is a chore.

So, I thought, what if I could push a button and a templated piece of code would be automatically inserted anywhere into my designer, Lotus Script, Java Script, Formula, you name it?

This tip will allow you to paste templated text into your designer, all by using the Tools Menu Bar. This code could be extended to work on templates stored in a Lotus Notes DB or offer prompt choices, but I thought that a simple example is the best way to explain it.

Follow the example below to see how it works. The example shows a scenario in which I am working in the Designer and have just created a Script Library. The code below allows me to click on "Tools -- Sub Routine Insert", and the following templated Sub Routine will be added to the Script Library.

This has been tested with IE6 and works on Win98, @k and XP.

Code

Sub MySub() 
' **********************************************
' Created By <PersonName> 
on <Date Created>
'
' <Sub Description Here>
' 
' **********************************************
 gCurrentMethodName = "[MySub]"
 On Error Goto errHandle
 
 '<Code Starts Here>
 
 Exit Sub
' ********* Error Handling 
Code Here ******* 
errHandle: 
 Call LogError( Err, Error$)
 Exit Sub
End Sub

1. Use Notepad to create a text document called InsertSub.vbs

2. Paste the following code into InsertSub.vbs

' *********** Start Of Code *****
dim txtToPaste
txtToPaste =" Sub MySub() " & chr(13) & _ 
"' **********************************************" 
& chr(13) & _ 
"' Created By <PersonName> 
on <Date Created>" & chr(13) & _ 
"'" & chr(13) & _ 
"' <Sub Description Here>" & chr(13) & _ 
"' " & chr(13) & _ 
"' **********************************************" 
& chr(13) & _ 
" gCurrentMethodName = 
""[MySub]""" & chr(13) & _ 
" On Error Goto errHandle" 
& chr(13) & _ 
"" & chr(13) & _  
" '<Code Starts Here>" & chr(13) & _ 
"" & chr(13) & _  
" Exit Sub" & chr(13) & _ 
"' ********* Error Handling Code Here ******* " 
& chr(13) & _ 
"errHandle: " & chr(13) & _ 
" Call LogError( Err, Error$)" & chr(13) & _ 
" Exit Sub" & chr(13) & _ 
"End Sub"  & chr(13) 

Set objIE = 
CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.
clipboardData.SetData "text", txtToPaste
objIE.document.parentwindow.
clipboardData.GetData "text"
objIE.Quit
' ******* End Of Code *******

3. Save the document. For my example it is saved as h:InsertSub.vbs.

4. Go to the Tools Menu in the Lotus Designer.

5. Select 'Tools -- Add Tool'.

6. In the Tool Name box type 'Sub Insert'.

7. Leave the Tool Action on 'Run Program' and type in the exact name of the file you saved in step 3.

8. Leave the Context as '... Always' for the mean time and Click 'OK'.

9. Create a blank Script Library. Make sure your cursor in at the place in the library that you want your new subroutine to appear.

10. Click on 'Tools - Sub Insert' (this is the new tool you just created).

11. Answer Yes to the prompt that appears.

12. Voila. Now make a few more short cuts to save you hours of typing.

13. If you go mad and make lots of tools shortcuts it might be worth changing the context (Step 8) to only show the tool where it is needed. The example code for instance might be best moved from '...always' to the section titled 'Script Library Design' so it only shows up there. To do this click on 'Tools - Customize Tools', select the tool you want to move and drag it to the section you want it in.

14. Last notes: Do not remove the prompt from the code. It stops the formula from pasting before the script has finished running. Until we get a sleep command in formula this will have to suffice. Also, double quote all speech marks in the 'TextToPaste' string. The pipe symbol doesn't work in this context.

MEMBER FEEDBACK TO THIS TIP

Is something missing in the code? I tried it and it is put into a clipboard, but it is never pasted in. I also noticed that the author is referrring to a prompt (in point #14 listed above) which I can't find.

—Thomas A.

******************************************

I have the same comment; as pasted, the code is incomplete and does not run.

—Joel P.

******************************************

It looks like I missed a change to my documentation for Step 7. Sorry. Originally I was using a compiled program called from this code and forgot to update my document for Step 7. Again my apologies. Step 7 should read:

@Command( [Execute]; 
"h:\\pasteNewSub.vbs");
@If( @Prompt([YesNo]; 
"Paste From Clipboard?"; 
"This will paste text in from the clipboard.") = 
@True; @Command([EditPaste] ); "")

This should solve the problem.

—Shane Hollis, tip submitter

******************************************

While this is an interesting tip, a much better method can be found here: www.alanlepofsky.com/alepofsky/alanblog.nsf/dx/paste-information-application This method lets you store your code or code template in a Notes document. You then choose which document you want to grab and paste into designer. It is infinitely more flexible.

—Dave L.

******************************************

Unfortunately this previous comment is incorrect. The link he mentions above does not work in the Lotus Notes Designer client for pasting text into the Lotus Script Designer and other areas. It works great for the Lotus Notes Client and especially for storing and pasting rich text. However, my tip was expressly created for developers trying to paste templated text into the designer.

—Shane Hollis, tip submitter

Do you have more comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Shane Hollis. Please let others know how useful it is via the rating scale at the end of the tip. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Formula
View hidden fields on Lotus Notes/Domino forms
Case-insensitive @Unique version combines fields on Lotus Notes forms
Provide rich-text formatting via the Profile document and Formula
Using Formula language code to sort Lotus Notes messages by subject
How to create dynamic JavaScript in Notes Domino without formulas
Formula language button manages Deny Access list searches
Retrieve Lotus Notes names from a nested group using @DBLookup
Create a computed Lotus Notes field to list Personal Address Book names
Show multiple Lotus Notes document fields in a single view column
How to send a document as a link in a Lotus Notes email

JavaScript
Trap JavaScript runtime errors in Domino Web apps
JavaScript workaround fixes Lotus Notes 8.x PostOpen event issue
Write HTML and JavaScript in Notes view rows and columns on the Web
JavaScript detects Web browser type and version in Notes/Domino 8.0.2
JavaScript creates a jump box on a Lotus Notes Web form
How to create dynamic JavaScript in Notes Domino without formulas
Trap an attachment path via the Domino file upload control field
Converting Lotus Notes views to XML documents using JavaScript
Prevent errors on iFramed pages with JavaScript
How to add keyboard functionality for Lotus Notes documents

LotusScript
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication
LotusScript filters and attaches files to a Notes form

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts