Solved

Breaking code execution.

Posted on 2013-12-09
10
359 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
Comment Utility
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
Comment Utility
Thanks, Reg, but unfortunately this command does not work in Autocad VBA.
0
 
LVL 19

Expert Comment

by:regmigrant
Comment Utility
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
 
LVL 43

Author Comment

by:Saqib Husain, Syed
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 43

Author Comment

by:Saqib Husain, Syed
Comment Utility
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
Comment Utility
0
 
LVL 43

Author Closing Comment

by:Saqib Husain, Syed
Comment Utility
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
Comment Utility
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
Comment Utility
Not that I understand the theory completely but I surely can understand the conclusion;)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now