|
|
ADVISOR TIPS
Making LotusScript Subroutines More Global
Use these advanced techniques to make code more reusable.
A lot of times, your functions and subroutines will be limited to a single button or agent. In other words, all the csode is contained in a single object. But, sometimes, you will want to share code between two or more objects.
Be sure to catch Scott Good's
Lotus development sessions at
Lotus Advisor DevCon.
November 3-7, 2003
Fort Lauderdale, Florida |
For instance, you might have several Action Buttons in your form that all do slightly different things but which all, at some point, have to do a budget check. In that case, you wouldn't want to have the same budget check code repeated in each button. Not only would that be repeating work you've already done, it would be a real pain to maintain. Instead, you'd be a lot better off if there were some place to put code that can be shared among all the buttons.
The good news is that you can, of course. In fact, there are two ways to do it. If your function only has to be used within a single form, you can create a Global function within that form in much the same way you created Global variables. If your code has to be shared among two or more forms or if it's going to be used by views or agents, you'll want to use Script Libraries. Either technique is quick and easy to use.
Build Global functions and subroutines
To build Global functions, you don't necessarily have to use Global variables. But, just like within an individual button, unless you're using Global variables (at the Form level, not just within your button), you'll have to pass in any variables you want to share between the button and the function.
Creating the Global function itself is easy. To create a Global function, go to the (Globals) area of your form. (In R5, (Globals) is at the top of the list in the object browser window. In R4x, you'll have to find it on the drop-downs over the code window.) Within (Globals) are four objects: (Options), (Declarations), Initialize, and Terminate. This is the area where you want to create your Global function (or subroutine).
Two of these objects, Initialize and Terminate, start with "Sub.." and end with "End Sub". To create a new function from either of those objects, put your cursor after the "End Sub," create a new line, and type in either "Function" or "Sub" followed by the name of your function or subroutine.
The other two objects, (Options) and (Declarations), don't use the "Sub...End Sub" format. In Options, you'll find only the words "Option Public." In Declarations, there's nothing at all. But you can create your Global functions and subroutines from either of these as well. Just be sure to start on a blank line. Otherwise, it all works the same. You can create as many different Global functions and subroutines as you want.
Use Script Libraries to kick it up a notch
If your function is shared by two or more forms, or if it's going to be used by views or agents, you'll want to create a Script Library. For some reason, Script Libraries are intimidating to many competent coders, but they don't have to be. Script libraries are easy to set up and use.
To begin, go to the "Script Libraries" area of your database. In R5, it's under the "Resources" heading. Click on the "New Script Library" button to start a new library or open an existing one to add new functions to it. You'll see that the starting set of objects is just like that in the Globals area of a form. You have (Options), (Declarations), Initialize, and Terminate. Create new functions and subroutines in exactly the way I just described for building them in the form.
When you've finished creating your functions, save the Script Library. Just like with anything else, you'll have to give your library a name. Script Library names can't have spaces, so plan accordingly.
To use the functions from your Script Library in your code, there's one more step to take. Go back to your form (or agent or wherever you're going to use the code). Go to the (Globals) area and click on (Options). Add a new line and type the word "Use" and then, in quotes, the name of your Script Library, like this:
Use "MySpecialFunctions"
After you've done that, you can call the subroutines and functions from your Script Library as if they were in your form (or agent or whatever). You can use as many Script Libraries in your form as you want. To use more than one, put each one on its own line, like this:
Use "MySpecialFunctions"
Use "BudgetCheckProcessing"
Use "FormProcessing"
And so on. Like most everything else, Script Libraries are easy to use after you know the basics. See the article, "LotusScript Best Practices," in the May 2002 issue of Lotus Advisor magazine (http://LotusAdvisor.com) for more information about Script Libraries.
Technical Editor Scott Good is president and co-founder of Teamwork Solutions, Inc., an IBM Premier Partner and two-time Beacon Award Finalist. Scott has extensive experience planning and developing Lotus Notes workflow applications. Scott is a frequent speaker at Lotus Advisor Summit conferences and Lotus Notes user groups, seminars, and demonstrations throughout the United States. http://www.scottgood.com, http://www.teamsol.com, http://www.notesworkflow.com sgood@teamsol.com
Keyword Tags: Application Development, Component-Based Development (CBD), Components, Development, Forms, IBM, IBM Lotus Notes, IBM Software, Lotus, LotusScript, Programming, Tech: Development
ADVISORAMA Everybody should believe in something; I believe I'll have another drink. -- W. C. Fields, comedian (1880-1946)
|
ARTICLE INFO
Web Edition: 2003.09.11, Doc #11161
FREE ACCESS
|
SUBSCRIPTION STATUSYou are not signed-in. If you are a subscriber to this publication, sign-in above to access locked articles. To subscribe or renew go to www.AdvisorStore.com.
|

Get it all -- every current and past ADVISOR tech/business publication, now all-in-one subscription, with new articles and a huge reference library packed with expert advice, how-to and downloads. Subscribe now to get it all.![]() 
Read the advanced guide to creating custom business database solutions with FileMaker software. Subscribe now to gain access to all the archives and downloads.![]() 
Learn the fundamentals of using FileMaker Pro software. Every issue gives you step-by-step instructions on creating the databases you need. Subscribe now!![]()
![]()
![]()
 ![]()

Submit your tips, techniques and advice and let Advisor promote your business and build your career. Show the world what you know!![]()  ![]()
|
|