KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Executing sequential conditional methods using Case statements
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: September 23, 2005

Here is an exercise in executing sequential conditional methods involving simple/complex conditionals so that the process can trap out of testing at any point if there is failure (or no reason to continue).

$return:=FALSE
Case of
: (not (method1) )
: (not (method2) )
: (not (method3) )
else
$return:=TRUE
End Case

For each project method above, it is assumed the return value is
- TRUE if the method executed successfully
- FALSE if the method's requirements weren't met or an error occurred.

NOT (TRUE ) returns the value FALSE, so if all conditional statements above return TRUE, the ELSE condition will be entered and the return value from the Case statement will be TRUE, meaning the execution was successful.


Here is an example that illustrates its use: A user wants to compare two events on a calendar to see if they are related to him and are at the same time, because he won't be able to attend both at the same time.

The conditional statement could use methods such as
- Boolean <- InvolveCurrentUser ( Event1 ; Event2 )
- Boolean <- areSameDate ( Event1 ; Event2 )
- Boolean <- areSameTime ( Event1 ; Event2 )

`---------------------------------------------
$return:=FALSE
Case of
: (not (InvolveCurrentUser ( Event1 ; Event2 ) ) )
: (not (areSameDate ( Event1 ; Event2 ) ) )
: (not (areSameTime ( Event1 ; Event2 ) ) )
Else
$return:=TRUE
End Case
`---------------------------------------------

If this statement returns TRUE, the events involve the user and are at the same time. If either of the events don't even involve the user, there's no point in testing if they are the same date or time, so the code will cancel out of the conditional statement with a return value of FALSE, which saves processing time.