Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
To iif or not to iif = .t.
Message
From
01/06/2001 22:02:20
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00513276
Message ID:
00514126
Views:
14
> Ok, let's try:
> I have a function (or I thought today, better make it a form method, since it's called by a form), which allows me to modify structure (or only indexes) in our existing databases.
>
> This function receives array of choosen databases for modification. Then I start my processing. The main loop is for all elements in the array of databases, the inner loop is by tables in each database. I have to check for existance of database (first loop: if database doesn't exist, I log a message and proceed with other databases - here I use loop operator). In the inner loop by tables I check, if the table could be open exclusively for possible changes, if not, a message is logged and I process next table. Modify_Structure program has quite complicated logic itself with bunch of scans or loops.
>
> Now, I want allow user to terminate the whole process by hitting ESC. Not just terminate, but ask him: did he (she) really intend to cancel and if Yes, cancel the process, display stats and return back to the form. Answer "Yes" on this question sets oValid.lContinue property to false and I have to terminate.
>
> I asked here question about temination of inner loops few months ago, and the answer, I got, I had to exit from each inner loop. So, I put
>
>if !oValid.lContinue
>    exit
>endif
>in each inner loop. This code works fine, but reading this discussion got me thinking, that it might be not the best approach. That's why I ask gurus like you or George to help me with advice.

Well, basically I use one or more logical flags instead of EXIT etc. The flag condition is tested at the top of each processing branch or loop. That way, when the value of the flag is changed (by ESCAPE etc.), the branch or loop has a chance to close itself gracefully. Otherwise execution sequence could be yanked unceremoniously to an unexpected place, leaving tables open or locked, memvars or objects unreleased, etc.

As I've said elsewhere in this thread, EXIT, LOOP etc. are perfectly legal and if they work for you, fine. I can only express my experiences that enhancing and maintaining code that uses them is ultimately harder than if you structure your code to avoid their use.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform