18.01.2013 Views

LotusScript for Visual Basic Programmers - IBM Redbooks

LotusScript for Visual Basic Programmers - IBM Redbooks

LotusScript for Visual Basic Programmers - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Other Recent Language Additions<br />

Recent VBA and VB4 syntactical enhancements have been included in the<br />

current release of <strong>LotusScript</strong>. Statements like With and ForAll are found in<br />

<strong>LotusScript</strong>. As an example, ForAll allows you to easily do something to<br />

every item within a <strong>LotusScript</strong> collection, such as a list or an integer array:<br />

dim iSalary(20) as integer<br />

<strong>for</strong>all x in iSalary<br />

x = x * 1.5 ' let’s give them a raise they won’t <strong>for</strong>get!<br />

end <strong>for</strong>all<br />

Other interesting statements include Datatype (variable) which returns the<br />

datatype associated with the object you pass it. Datatype is similar to <strong>Visual</strong><br />

<strong>Basic</strong>’s If TypeOf statement, but requires a lot less work.<br />

Note that the <strong>LotusScript</strong> End statement is not directly equal to <strong>Visual</strong><br />

<strong>Basic</strong>’s End. The End statement in <strong>LotusScript</strong> stops the currently executing<br />

script, and to exit the application in the way you would with <strong>Visual</strong> <strong>Basic</strong>’s<br />

End, you generally use the appHalt function. If you are within Lotus Notes,<br />

you can use the Close macro to easily (and safely) shut the application<br />

down.<br />

Error Handling<br />

<strong>LotusScript</strong> provides the same type of error handling syntax as <strong>Visual</strong> <strong>Basic</strong><br />

Release 4, allowing <strong>for</strong> Err, Erl, Error, Resume, Resume Next, On Error<br />

Goto label, and so on.<br />

For example, the following code can be used in both <strong>LotusScript</strong> and <strong>Visual</strong><br />

<strong>Basic</strong>.<br />

Sub cmdUpdateDB_Click ( )<br />

cmdUpdateDBErr:<br />

10 <strong>LotusScript</strong> <strong>for</strong> <strong>Visual</strong> <strong>Basic</strong> <strong>Programmers</strong><br />

On Error GoTo cmdUpdateDBErr:<br />

' process database updates here...<br />

Exit Sub<br />

' The HandleErr( ) call provides a way to<br />

' centralize your error processing. The code <strong>for</strong><br />

' the HandleErr call is shown in the<br />

' object-oriented section below.<br />

If HandleErr(Err, Error$, _

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!