API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Setting Default Boolean Values
This tip came about from some code seen on Notes Net that was posted by Cesar Mugnatto. Looking at that code, a good technique for dealing with Boolean variables in generic functions was demonstrated.

Whenever you write a generic function (which we do many times, as you can see from looking at our many hints and tips), you have to deal with parameters passed in that aren't quite right. LotusScript will deal with mismatched data types, so you couldn't pass in a String when the parameter says an Integer should be passed. However, up until the time that Notes/Domino 6 is being used widely, True/False values need to be passed into Integer variables. (Notes/Domino 6 has a Boolean data type that can be used). Storing a Boolean value in an Integer variable is not a new technique, but dealing with a "default value" in a generic function is. (Incidentally, you could store the Boolean value in a Variant variable, but that takes up more storage space and you should still use this technique).

Let's say that you have written a generic function or subroutine and a Boolean value will be passed in as a parameter:

Sub MySub(Parm1 As Integer)

Since the data type is Integer, technically all these calls are correct:

MySub(True)
MySub(False)
MySub(100)
MySub(-50)

So, in the last two cases, we would want the function to come up with some "default" value since the passed-in value isn't what was expected (it's not True or False). If you want the function to default to True, then add this code at the start of your function:

Parm1 = (Parm1 = True)

That line says that if Parm1 = the constant True (or the integer equivalent, which is -1), then Parm1 is True. If it is anything else, then Parm1 is set to False.

If you would like False to be the default instead, add this code at the start of your function:

Parm1 = Not (Parm1 = False)

That line says that if Parm1 = the constant False (or the integer equivalent, which is 0), then Parm1 is False. (False = False is True, then it is inverted to result in False). If it is anything else, then Parm1 is set to True. (??? = False is False, then it is inverted to result in True).

From this point on, the code can safely know that Parm1 is either True or False.