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.

Conditional Compilation<br />

Conditional compilation provides a way <strong>for</strong> developers to code in plat<strong>for</strong>m<br />

or similarly specific sections of code, with only the code pertaining to the<br />

runtime plat<strong>for</strong>m actually being compiled when executed. The following<br />

<strong>LotusScript</strong> If statements, preceded by “%” character, are used <strong>for</strong><br />

conditional compilation.<br />

%If<br />

%ElseIf<br />

%End If<br />

The above statements provide conditional compilation support and work in<br />

the same way as the #If ... #End If statements do within <strong>Visual</strong> <strong>Basic</strong> 4.0.<br />

You follow the %If or the %ElseIf with a constant that is provided by the<br />

language or declared explicitly by the developer.<br />

<strong>Visual</strong> <strong>Basic</strong> allows you to define your own constants using a #Const<br />

compiler directive. This allows you to add #If DEBUGGING type of logic in<br />

the application, providing a way to compile out all debugging code simply<br />

by removing a #Const DEBUGGING line.<br />

Otherwise, both <strong>LotusScript</strong> and <strong>Visual</strong> <strong>Basic</strong> come with preset constants to<br />

use with conditional compilation statements. Code written like this shows<br />

the Win32 and OS/2 conditional compilation constants in use:<br />

%If Win32<br />

messageBox("Running on Win32")<br />

%ElseIf<br />

%If OS/2<br />

messageBox("Running on OS/2")<br />

%End If<br />

%End If<br />

This will display a message box telling the user what plat<strong>for</strong>m the code is<br />

running on. The unreachable code is not executed at all.<br />

Lotus recognizes more plat<strong>for</strong>ms than Microsoft as being legitimate porting<br />

possibilities. Microsoft supports Win32 and Win16 as constants provided by<br />

the language. In <strong>LotusScript</strong> you will find compiler directives <strong>for</strong> almost<br />

everything from SOLARIS to OS/2. Lotus also adds the MAC as a real<br />

alternative to Win“xx” as well. Using <strong>LotusScript</strong> within Notes provides a<br />

way to build truly cross-plat<strong>for</strong>m, portable applications.<br />

The %If, %End If statements are not provided in Lotus Notes.<br />

12 <strong>LotusScript</strong> <strong>for</strong> <strong>Visual</strong> <strong>Basic</strong> <strong>Programmers</strong>

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

Saved successfully!

Ooh no, something went wrong!