My.ADVISOR.com Sign-In
ID
Password

Member Center / Sign-Up
Go to Article
Advanced Search 

ADVISOR TIPS

Making LotusScript Subroutines More Global

Use these advanced techniques to make code more reusable.

By Scott Good


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.


This tip is an excerpt from Scott's article "Leverage LotusScript Functions and Subroutines" in the June 2002 issue of Lotus Advisor magazine.

Making LotusScript Subroutines More Global

1 reader comment:

What do YOU think about this topic? Share your advice and thoughts using this form.

Your Name

REQUIRED : PUBLIC

Your E-Mail

REQUIRED : PRIVATE

Job, Company

OPTIONAL : PUBLIC

City, State, Country

OPTIONAL : PUBLIC

Your Web Site

OPTIONAL : PUBLIC

Your Comment

Please help everyone by keeping your comments on-topic, using clean language, and not defaming or making personal attacks.


Your e-mail address is required, but it will not be displayed to the public or given to anyone. See our Privacy Policy. Comments become visible after they pass our spam filter, and spammers and abusers are permanently blocked. Please report spam or abuse.

Scott GoodTechnical 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

Printer-friendly
page layout

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

DataBased Advisor

Web Edition: 2003.09.11, Doc #11161

FREE ACCESS FREE ACCESS

SUBSCRIPTION STATUS
You 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.

Subscribe to DATABASED.ADVISOR.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.

DataBased.Advisor.com

Subscribe to FileMaker Advisor Magazine

Read the advanced guide to creating custom business database solutions with FileMaker software. Subscribe now to gain access to all the archives and downloads.

FileMaker.Advisor.com

Subscribe to Advisor Basics of FileMaker Pro

Learn the fundamentals of using FileMaker Pro software. Every issue gives you step-by-step instructions on creating the databases you need. Subscribe now!

FileMaker.AdvisorBasics.com

Showcase Your Smarts

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

AdvisorTips.com

Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
Portions copyright ©1983-2008 Advisor Media, Inc. All Rights Reserved.
Reuse or reproduction of any portion or quantity of Advisor Media's copyrighted content, in any form, for any purpose, requires written permission.
ADVISOR®, the ADVISOR logo, and other names and logos that incorporate ADVISOR are registered trademarks, trademarks or service marks of Advisor Media, Inc. in the United States and/or other countries.
Other trademarks are used for identification, editorial or descriptive purposes and are the property of their owners.
Hosted by Prominic.NET Website powered by
LOTUS SOFTWARE
GOODX14 posted 09/11/2003 modified 01/07/2009 03:40:41 AM ztdbms/ztdbms
domino-144.advisor.com my.advisor.com 01/07/2009 01:10:52 PM