Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Hate Nested IFs? Consider this...
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 2000 SP4
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01086217
Message ID:
01086319
Views:
22
>>>
>>>SELECT c_letter_series_masters
>>>DO CASE
>>>   CASE myLookup("cDepartment_code=lcDepartment_code AND cClient_code=lcClient_hospital_id")
>>>      lcLetter_series_masters_pk = c_letter_series_masters.cLetter_series_masters_pk
>>>      llFound = .T.
>>>   CASE myLookup("cDepartment_code = lcDepartment_code")
>>>      lcLetter_series_masters_pk = c_letter_series_masters.cLetter_series_masters_pk
>>>      llFound = .T.
>>>   CASE myLookup("cClient_code = lcClient_hospital_id")
>>>      lcLetter_series_masters_pk = cLetter_series_masters_pk
>>>      llFound = .T.
>>>   OTHERWISE
>>>      =MESSAGEBOX("Nothing found")
>>>      llFound = .F.
>>>ENDCASE
>>>
>>>
>>>FUNCTION myLookup
>>>LPARAMETERS tcLookup
>>>LOCATE FOR EVAL(tcLookup)
>>>RETURN FOUND()
>>>
>>>
>>
>>LOL. I should have said without using functions. Also would you agree that this change would slow the code execution considerably if you're running this code in a loop? <g>
>
>Two things -- I personally would not rewrite someone else's "nested IF" code as long as it did what it was expected to do. Second, the ONLY time I have gone to a DO CASE instead of the nested IFs is when I am calling methods within a class in order to do a massive amount of processing where I have to trap failures and prevent the execution of the subsequent CASE statements.

Each case has its merit - no disagreement here <g>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform