Solved

Breaking code execution.

Posted on 2013-12-09
10
377 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

SendBlaster Pro 4 - Bulk Email Sending Software

SendBlaster 4 Pro - Best Bulk Emailing Sending Software
Automatic Subscribe / Unsubscribe Processing
Great for Newsletters & Mass Mailings
Optional HTML & Text Composition
Integration with Google Features
Built in Spam Score Checking
Free Professional Templates - Feature Packed!

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 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