Again something learned.
I just finished a new macro, where I worked for the first time with multiple subs to structure the code a bit. One of the additional subs has no reference
The macro worked without problems in the editor. If the mouse pointer did not point to the sub main, I had to select in the popping up window which sub should be executed.
The tide turned when I tried to start the macro with the execute button. Then nothing happened!
A post in the good old forum brought me to the right track: https://forum.solidworks.com/thread/226354
In my ignorance I assumed that the execute button always calls the sub main. But that is probably not so!
If you create your own button for the macro, you can specify the start procedure. But what do you do if you have macros that are only started by the execute button?
Add a reference to all additional subs, or change the subs without references to function, so that only the sub main is left to start?
Or are there other solutions? What is the clean way?
Macro with multiple subs without references.
Macro with multiple subs without references.
All the "good" news about SWX makes me feel like I'm driving a truck with two trailers straight into a dead end.
Re: Macro with multiple subs without references.
I like to add optional arguments that don't do anything. Like:
Sub NotMain(Optional NotMeDummy as Long)
This will keep the execute button from calling them, and also prevent some user from mapping the macro button incorrectly.
Multiple options for start routine are actually useful sometimes. It allows you to have one macro with multiple different start options. For example, I have a macro that moves windows right and left inside SW. Most of the code to find windows, measure desktop, etc. is all common whether the window needs to move right or left. So I call two different start routines within the same macro depending on which way the window needs to move. If I need to modify the common code I only need to do it once.
Sub NotMain(Optional NotMeDummy as Long)
This will keep the execute button from calling them, and also prevent some user from mapping the macro button incorrectly.
Multiple options for start routine are actually useful sometimes. It allows you to have one macro with multiple different start options. For example, I have a macro that moves windows right and left inside SW. Most of the code to find windows, measure desktop, etc. is all common whether the window needs to move right or left. So I call two different start routines within the same macro depending on which way the window needs to move. If I need to modify the common code I only need to do it once.
Re: Macro with multiple subs without references.
Like you already mentioned, my go to method is to just make everything but the "main" a function that returns a boolean or something. If I use the value at all, I'd use that to tell me if the function completed with or without error.