?
Solved

Breaking code execution.

Posted on 2013-12-09
10
Medium Priority
?
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

718 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