Solved

Breaking code execution.

Posted on 2013-12-09
10
372 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

680 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