The tips on this page are so obvious and simple as to be easily overlooked, but using them can make development a lot easier.


Writing Show-When formulas

Quite often there will be times when it would be much easier if you could specify a show-when formula, there will always be occasions when the required logic of a formula seems needlessly confusing, and this often ends up leading to errors. Luckily it is very easy to work around the limitation of only being able to provide a hide-when formula.

So how do you turn a Hide-When into a Show-When? Like this...

!(formula)

It really is that simple, just write a Show-When formula and enclose the whole piece of code in parenthesis, and negate it. Not hiding something is showing.


Using an inline "If" statement

The If statement is probably the most useful and fundamental command used in programming, but sometimes in your LotusScript code it would be nice to have some of the functionality of the @If formula, specifially the ability to be able to use If as a function.

Look at this example:

Var := "I counted " + NumberOfThings + " item" + @If (NumberOfThings > 1; "s"; "");

Now try doing that in LotusScript... in one line. The fact is it cannot be done with the built in functions of LotusScript, but there is a very simple way to remedy this by creating an IIf function. It may seem like more effort than using an extra line if all you want to do is translate the above formula, but this is a function that once you have it you will find yourself using it repeatedly. Not only does it make things simpler it makes your code a lot more readable.

Function IIf (Condition As Variant, TrueCondition As Variant, FalseCondition As Variant) As Variant

   If Condition Then
      Let IIf = TrueCondition
   Else
      Let IIF = FalseCondition
   End If

End Function

To use the fomula you just pass the condition as the first parameter, whatever you want to be returned if the condition is true as the second parameter, and the false condition as the third parameter.

result = IIf (Condition, TrueCondition, FalseCondition)

Here's the function example again, now in a single line of LotusScript:

Let Var = "I counted " & CStr (NumberOfThings) & " item" & IIf (NumberOfThings > 1, "s", "")

Incidentally IIf stands for "Immediate If" and not "inline if".


More soon...

More tips will be added to this page so keep checking back.