nkormanik Posted June 14, 2023 Report Share Posted June 14, 2023 Suppose a macro is presently running. Nickname: XYZ I would like to immediately start a new macro. Nickname: ABC. But I want the running macro to be stopped cold, dead in its tracks. Looking over the possibilities, "Terminate Process" seems the only way to do this, via script. I would put that at the beginning of the new macro. In order to use "Terminate Process" one must use the Process Name. Does a presently running macro have a Process Name? Best that it be generic. As in, ANY running macro must be immediately terminated. Then continue on with the new macro, and continue executing it. Not sure if what I am asking is possible. Please advise. Thanks, Nicholas Kormanik Quote Link to comment Share on other sites More sharing options...
Cory Posted June 14, 2023 Report Share Posted June 14, 2023 Why wouldn't you use the Macro Stop command? Also I prefer to put something in XYZ that would watch for a command to terminate. YO udon't want to terminate the MEP process becasue that woudl terminate MEP that's also trying to run ABC Quote Link to comment Share on other sites More sharing options...
nkormanik Posted June 14, 2023 Author Report Share Posted June 14, 2023 If ABC macro issues a Macro Stop as its first line, would it cause XYZ -- which is currently running -- to stop? From the help site: Macro Stop The Macro Stop command stops the execution of a macro. Use this primarily in conjunction with a conditional statement. If a desired condition is not met, terminate the macro. Quote Link to comment Share on other sites More sharing options...
rberq Posted June 14, 2023 Report Share Posted June 14, 2023 MACRO STOP stops the macro that contains it. I don't think there is a command you can execute in Macro ABC that will stop Macro XYZ. If XYZ is a long-running macro, I assume it has some kind of REPEAT loop. You could have XYZ check "something" each time through the loop -- for example, check for whether file XYZSTOP exists. If the file exists, XYZ does a MACRO STOP to kill itself. When Macro ABC starts running, the first thing it does is create file XYZSTOP. 1 Quote Link to comment Share on other sites More sharing options...
Cory Posted June 14, 2023 Report Share Posted June 14, 2023 Oh of course. Sorry. I never have this need because as I and rberg suggested I always have the first macro terminate itself at the request of the second macro. Quote Link to comment Share on other sites More sharing options...
nkormanik Posted June 14, 2023 Author Report Share Posted June 14, 2023 7 hours ago, rberq said: MACRO STOP stops the macro that contains it. I don't think there is a command you can execute in Macro ABC that will stop Macro XYZ. If XYZ is a long-running macro, I assume it has some kind of REPEAT loop. You could have XYZ check "something" each time through the loop -- for example, check for whether file XYZSTOP exists. If the file exists, XYZ does a MACRO STOP to kill itself. When Macro ABC starts running, the first thing it does is create file XYZSTOP. Pretty clever, rberq. Please provide some code doing this.... Quote Link to comment Share on other sites More sharing options...
acantor Posted June 14, 2023 Report Share Posted June 14, 2023 Rberq's method works. The first macro, which runs for about ten seconds, checks for the existence of a specific file each time it loops. That file is Test.txt. (When the first macro begins, it deletes Test.txt.) So the file doesn't exist when the first macro is running uninterrupted. When the second macro begins, the first thing it does is create the file that the first macro monitors. It creates the file by making a copy of a Test.txt backup file. The copy is this: c:\tmp\Test (Copy).txt To set this up, you'll need to create this file. Mine is an empty file. First macro: Delete File/Files: "c:\tmp\test.txt" Delay: 500 milliseconds Text Box Display: First macro Repeat Start (Repeat 10 times) Text Box Update: First macro If File Exists: "c:\tmp\test.txt" Text Box Close: First macro Macro Stop End If Delay: 1000 milliseconds End Repeat <DELETE FILE/FILES Path="c:\\tmp\\test.txt" Progress="FALSE" Recurse="FALSE" Permanent="FALSE"/> <DELAY Flags="\x02" Time="500"/> <COMMENT/> <TEXT BOX DISPLAY Title="First macro" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %Count%\\fs14 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x01" Delay="0"/> <COMMENT/> <REPEAT START Start="1" Step="1" Count="10" Save="TRUE" Variable="%Count%"/> <TEXT BOX UPDATE Header="First macro" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %Count%\\fs14 \r\n\\par }\r\n"/> <IF FILE EXISTS File="c:\\tmp\\test.txt" Search_Path="FALSE"/> <TEXT BOX CLOSE Header="First macro"/> <MACRO STOP/> <END IF/> <DELAY Flags="\x02" Time="1000"/> <END REPEAT/> Second macro: Copy File/Files: "c:\tmp\Test (Copy).txt" to "c:\tmp\Test.txt" Delay: 500 milliseconds Text Box Display: Second macro <COPY FILE/FILES Source="c:\\tmp\\Test (Copy).txt" Dest="c:\\tmp\\Test.txt" Progress="FALSE" Recurse="FALSE"/> <COMMENT/> <DELAY Flags="\x02" Time="500"/> <TEXT BOX DISPLAY Title="Second macro" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs14 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> Quote Link to comment Share on other sites More sharing options...
Cory Posted June 14, 2023 Report Share Posted June 14, 2023 I use the registry. For my big macros I usually set up a key for my macro stuff including controls. Another way I have done it is to have the first macro checks for the existence of a window title or control. The control or text would be the message box displayed by the second macro. Quote Link to comment Share on other sites More sharing options...
acantor Posted June 14, 2023 Report Share Posted June 14, 2023 I imagine that using the Registry is the most elegant way to set a flag that a macro needs to be stopped. Personally, I hesitate using the Windows Registry to store values, although the once or twice I tried to do it, the sun still rose the next morning! Quote Link to comment Share on other sites More sharing options...
Cory Posted June 14, 2023 Report Share Posted June 14, 2023 I used to write distributed MEX files with many users and it was almost like a program. Having that registry worked well and had fewer problems that file based solutions. Also I could edit the registry remotely. But the window title trick is nice too. Most times the interrupting macro needs some kind of interface, so just use that. XYZ sees a window title "Macro ABC" pauses, then pops up a box asking if the user wishes to terminate or continue. Say ABC does some little thing quickly for the user and then wants XYZ to continue. Click that button and it does without having to restart the macro. Quote Link to comment Share on other sites More sharing options...
nkormanik Posted June 14, 2023 Author Report Share Posted June 14, 2023 The button press to terminate current macro (what ever we set that to be in settings; pause, in my case) perhaps is an easy way to go about the above. Adds an exta step, though. Bummer. So I might go with your suggestions..... Quote Link to comment Share on other sites More sharing options...
Cory Posted June 14, 2023 Report Share Posted June 14, 2023 You could also terminate the macro from the "Forrest Gump" icon in the System Notification Area. No macro required. And you can make it so Forrest is always apparent when a macro is running. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.