10 Advanced LotusScript tips2

Source: Internet
Author: User
Tags mul
    1.  

      Class inheritance

    2. Use platform-specific LotusScript code with classes
    3. Use version-specific LotusScript code with classes
    4. Use lsi_info ()/getthreadinfo
    5. Use the Execute Command
    6. Use advanced logging
    7. Mixing Java and LotusScript

Advanced LotusScript Tip #1. Understand binding

 

There are two types of binding:Early bindingAndLate binding.

Early binding is set by the compiler and works well because it uses type checking, works quickly and is easy to use. An example of early binding might be:

 
Dim s as string

Late binding is set at runtime. it is very flexible, but doesn' t use type checking. unfortunately, the performance isn' t as good as early binding and you might run into some runtime errors.

 
Dim V as variantdim s as new notessessionset v = S. currentdatabaseprint v. gettitle ()

Advanced LotusScript Tip #2. Code for performance

 

When you're coding for performance, always remember that expensive operations include opening Lotus Notes databases, and views and documents with lots of fields. so, when you're collecting data, remember to cache views wherever possible and useNotesviewentryInstead of opening documents.

As an example, let's say you have a Lotus Notes database with 100,000 documents in it. this wocould take seven hours to actually open every document in the Lotus Notes database, if you don't code for performance and use views. if you do code for performance, it will only take you 60 minutes to open these using notesview and only 12 minutes if you useNotesviewentry!

Advanced LotusScript Tip #3. Use lists and Classes

 

It's good practice to use Lotus script lists and classes because classes bind complex data and operations. lists can look these up quickly in memory. for a quick example, here's how we might extend our person class:

Dim people list as persondim peoplebyunid list as persondim P as new person ("Joe Bloggs/Acme", "010101010201020 ").... set people (p. getname) = pset peoplebyunid (P. getunid) = PIF (iselement (People ("Joe Bloggs/Acme") Then _ print "Joe's unid is:" + people ("Joe Bloggs/Acme "). getunidif (iselement (peoplebyunid ("010101010201020") Then _ print "unid '000000' is:" + _ peoplebyunid ("010101010201020 "). getname

Advanced LotusScript Tip #4. Use class inheritance

 

Class inheritance allows us to "extend" classes to add functionality. For example:

Class staffperson as personprivate strstaffid as stringsub new (strnewperson as string, strnewunid as string) end subpublic function setstaffnumber (newno as string) strstaffid = newnoend functionpublic function getstaffnumber as between = me. extends functionend

Advanced LotusScript Tip #5. Use platform-specific code with classes

 

Dim s as new notessessiondim mem as variantselect case s. platformcase "Windows/32" set mem = new getmemw32 () Case "Aix" set mem = new getmemaix () case elseprint "platform not supported" set mem = nothingend caseif (not mem is nothing) thencall mem. printmemory () Class getmemfunction getmem () as longgetmem = 0end functionsub printmemoryprint me. getmem () end subend classclass getmemw32 as getmemfunction getmem () as longgetmem = getwindowsmemory () end functionend classclass getmemaix as getmemfunction getmem () as longgetmem = end functionend class

Advanced LotusScript Tip #6. Use version-specific code with classes

 

Dim s as new notessessiondim VCU as variantselect case s. versioncase 5 set VCU = new createuser () Case 6 set VCU = new createuserv6 () Case elseprint "version not supported" set VCU = nothingend caseif (not VCU is nothing) then _ call VCU. createuser (....) class createuserfunction createuser (...) as integer .... end functionend classclass createuserv6 as createuserfunction createuser (...) as integer .... end functionend class

7. Use lsi_info ()/getthreadinfo

 

You can useLsi_info ()Command to get some runtime information. Be aware though that this information is superceded byGetthreadinfoCommand.

If you useGetthreadinfo (11), That will return you the calling class. If you useGetthreadinfo (10), That will return you the function name. And these are just the beginning.

Through error trapping, we can track where we came from. We don't have to pass lists of parameters to error trapping code. It also prevents coding errors through using the copy and paste method.

Here is an example of this in use, preceded by the calling code:

 
'Calling code... exitfunction: Exit functionerrorhandler: Call raiseerror () Resume exitfunctionend Function

Function raiseerror () dim thistype as stringdim es as stringthistype = typename (me) 'not a class, use the calling module insteadif (thistype = ") Then thistype = getthreadinfo (11) es = thistype & ":" & getthreadinfo (10) & ":" If (ERR = 0) thenes = es + "manually raised an error" elsees = es + "Run Time Error: (" + trim (STR (ERR) + ") "+ _ error $ +" at line: "+ trim (STR (ERL) end ifprint esend Function

Advanced LotusScript Tip #8. Use the Execute Command

 

By using the Execute Command, you can run Lotus script from a string. Doing This accommodates version/platform differences at runtime. Here's an example:

Dim executestring as stringexecutestring = | print "Hello World" dim s as new notessessiondim dB as notesdatabaseset DB = S. currentdatabaseprint "Current Database Name is:" + dB. Title | execute (executestring)

Advanced LotusScript Tip #9. Use advanced logging

 

By using the openntf "openlog" solution, you can make simple LotusScript library additions to your code, provide "called from," "error," and "line number" functionality. our system now works on error trap and displays all objects in memory.

Advanced LotusScript Tip #10. Mixing Java and LotusScript

 

By mixing Java and LotusScript together, you can really get the most out of each scripting language. the trick is to use each language to its strengths. for example, Java is good for Web Service, Network I/O, and multithreaded operations. lotus script is the traditional Lotus Notes development language and works in the user interface.

Mixing the two versions ages together is easy -- just call an agent, passing a Lotus Notes document.

You shoshould also know that this works both ways, as you can call Java from LotusScript. This is calledLs2j. An example is below:

// Create a script library of type "Java" called xlib // containing the following function: public class calculator {public int add (int A, int B) {return a + B;} public int Div (int A, int B) {return a/B;} public int MUL (int A, int B) {return a * B;} public int sub (int A, int B) {return a-B ;}}

 
Option publicuse "xlib" uselsx "* javacon" sub initializedim mysession as javasessiondim myclass as javaclass, calculator as javaobject, A, B, C as integerset mysession = new javasession () set myclass = mysession. getclass ("Calculator") set calculator = myclass. createobject () A = 10b = 5C = calculator. mul (a, B) MessageBox "a * B =" & Cend sub

Tutorial: 30 Lotus script tips

Home: Introduction
Part 1: 10 fundamental LotusScript tips
Part 2: 10 everyday LotusScript tips
Part 3:10 Advanced LotusScript tips
Part 4: More Lotus script Learning Resources

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.