Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CASE statements
Message
From
21/10/2003 17:54:11
 
 
To
21/10/2003 16:28:44
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00838740
Message ID:
00840861
Views:
22
I'm not sure that I understand your adversion to Do Case structures doing "work", but everyone is entitled to his own style and standards. I have found DO CASE to be very useful. Especially in "cases" where any one of many conditions is FALSE aborts the work to be done.

Also in "cases" where there is a possibility of multiple positive conditions that may exist but there exists a hierarchy where only one is to be allowed to do some "work" to the exclusion of all other "work" for any of the other lesser significant conditions, DO CASE is ideal. It allows you to avoid multiple nested If/Else/Endif structures or additional flag variables and IMO it provides well formatted code that is possibly easier to read and understand the intent. It may also allow a single exit point without nested if/else/endif or additional flag variables to check for.

m.llCondition1 = .t.
m.llCondition2 = .f.
m.llCondition3 = .t. && but do not process if any previous m.llCondition is .t.
m.llCondition4 = .f.
DO CASE     
   CASE m.llCondition1 = .t.
      *!* do required work when m.llCondition1 is .t. and skip any other processing for other Conditions

   CASE m.llCondition2 = .t.
      *!* do required work when m.llCondition2 is .t. and skip any other processing for other Conditions
   
   CASE m.llCondition3 = .t.
      *!* do required work when m.llCondition3 is .t. and skip any other processing for other Conditions

   CASE m.llCondition4 = .t.
      *!* do required work when m.llCondition4 is .t. and skip any other processing for other Conditions
   
   OTHERWISE
      *!* do required work when no Condition is .t. 

ENDCASE  
Or do the same thing with if/endif requires (IMO) confusing nested if/else/endif structures or multiple exit points.
IF m.llCondition1 = .t.
      *!* do required work when m.llCondition1 is .t. and skip any other processing for other Conditions

ELSE

    IF m.llCondition2 = .t.
      *!* do required work when m.llCondition2 is .t. and skip any other processing for other Conditions

    ELSE
         IF m.llCondition3 = .t.
             *!* do required work when m.llCondition3 is .t. and skip any other processing for other Conditions

         ELSE
              IF m.llCondition4 = .t.
                   *!* do required work when m.llCondition4 is .t. and skip any other processing for other Conditions

              ELSE
                   *!* do required work when no other Condition is .t. 

              ENDIF
         ENDIF
   ENDIF
ENDIF
Or using multiple if / endif combined with otherwise unnecessary m.llWorkdone flag
local m.llWorkdone
m.llworkdone = .f. 
IF m.llCondition1 = .t.
      *!* do required work when m.llCondition1 is .t. and skip any other processing for other Conditions

      m.llWorkdone = .T. 
ENDIF

IF m.llWorkdone = .f. AND m.llCondition2 = .t.
      *!* do required work when m.llCondition2 is .t. and skip any other processing for other Conditions

      m.llWorkdone = .T.
ENDIF   

IF m.llWorkdone = .f. AND m.llCondition3 = .t.
      *!* do required work when m.llCondition3 is .t. and skip any other processing for other Conditions

      m.llWorkdone = .T. 
ENDIF

IF m.llWorkdone = .f. AND  m.llCondition4 = .t.
      *!* do required work when m.llCondition4 is .t. and skip any other processing for other Conditions

      m.llWorkdone = .T. 
ENDIF

IF m.llWorkdone = .f.
      *!* do required work when no Condition is .t. 

      m.llWorkdone = .T. 
ENDIF  

Previous
Next
Reply
Map
View

Click here to load this message in the networking platform