Solved

Breaking code execution.

Posted on 2013-12-09
10
369 Views
Last Modified: 2013-12-13
Typically, when VBA code is running it is possible to interrupt execution by pressing Esc key or Ctrl-Break. This has always worked well in excel but I am having problems in Autocad where neither option works. Is there any setting which disables breaking in VBA?
0
Comment
Question by:Saqib Husain, Syed
  • 5
  • 5
10 Comments
 
LVL 19

Expert Comment

by:regmigrant
ID: 39708183
you can stop break with Application.EnableCancelKey = xlDisabled

I think it also raises error 18 so that could be trapped and 'resumed'.


Reg
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39708305
Thanks, Reg, but unfortunately this command does not work in Autocad VBA.
0
 
LVL 19

Expert Comment

by:regmigrant
ID: 39708334
I think the equivalent in AutoCAD uses a library function to detect key pushes - its been a while but GetKeyState  or something similar was used to detect a key push then an error handler checked for escape key and closed out procedures.

Reg
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39708379
Does that mean that I have to add this statement to all pieces of code which I write?....and if I forget then I have to crash Autocad.
0
 
LVL 19

Expert Comment

by:regmigrant
ID: 39708420
I'm working from quite old memories here but as I recall we added it to all projects as part of the style guide for the organisation and if someone forgot they were in deep trouble so I'm guessing that's a yes.  It only had to be added once at the top of the code so it was just included as a matter of course most of the time and whilst the basic function was to trap escape requests it was used for all sort of extras like displaying a progress summary and the like when P was pressed.

I seem to remember that repeatedly pressing escape sometimes caused an error condition which gave rise to a 'continue/cancel' box but we found that a) it was hit or miss that it would work and b) it did absolutely no clean up of processes, handles, etc - its was effectively an 'end' so the drawing always had to be reloaded at that point or would be wobbly ever after.


This might have changed in later versions so all I can suggest is the community forum at autodesk.com - it used to be quite lively

Reg
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39716003
I have been unable to find the correct command for getkeystate.

Can anyone find it for me?
0
 
LVL 19

Accepted Solution

by:
regmigrant earned 500 total points
ID: 39716230
0
 
LVL 43

Author Closing Comment

by:Saqib Husain, Syed
ID: 39716455
That is simply horrible. I can easily forget placing the check in my loop. I wonder why they cannot let it be interruptible using the esc or break key as it is in excel. Anyway thanks for the effort.
0
 
LVL 19

Expert Comment

by:regmigrant
ID: 39716663
I agree its clunky but it was explained to me along these lines:-

imagine you coded multiple processes which are triggered when, for example, you link two shapes together. Halting execution could potentially leave a partially committed transaction where one shape has been completed but the other is still being processed. This may not be reflected on screen, Further manipulation could cause problems such as drawing corruption, or crashing the drawing altogether with no way of knowing which shape needs to be deleted. More importantly the incomplete but visually correct object could be modified by normal drawing process and the error pass unnoticed until the data is found to be wrong - potentially once the design has been committed for work

Since Autodesk could not easily provide a single solution covering all eventualities they took the easy way out and just stopped anyone breaking out of the code until its complete.



Reg
0
 
LVL 43

Author Comment

by:Saqib Husain, Syed
ID: 39716732
Not that I understand the theory completely but I surely can understand the conclusion;)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you how to use shortcut menus in the Access run-time environment.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question