Jump to content
Macro Express Forums

Closing a launched program?


Recommended Posts

This is probably glaringly obvious, but ... what's the simplest way to handle the following frequent requirement please? Suppose I have a macro that uses a program, say Notepad, that may or may not already be running when the macro is activated. So I use Activate or Launch at the start of the macro. But what's the easiest way to close Notepad again at the end of the macro, but only if it was launched? If it was already open then I want to leave it open.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

You could probably split your macro in an 'if program running" and "if not program running" section.

 

Thanks, yes, that's certainly one approach.

 

But, given that ME Pro 'knows' that it's had to launch the program, I'm wondering if there's some indication of that I could access somehow?

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

... given that ME Pro 'knows' that it's had to launch the program, I'm wondering if there's some indication of that I could access somehow?
I don't think ME stores any indicator that you can access. However, as Phonemes says, why not make your own indicator? Do a simple test, before the ACTIVATE OR LAUNCH, where you set a switch to be checked at the end of your macro.

 

IF PROGRAM 'NOTEPAD' RUNNING

VARIABLE SET T99 = 1

END IF

 

ACTIVATE OR LAUNCH

 

OTHER MACRO STUFF

 

IF T99 <> 1

TERMINATE PROCESS 'NOTEPAD'

END IF

 

If there are multiple instances of NOTEPAD running, TERMiNATE closes one instance -- in my testing, it seems to close the one that was chronologically the first one started. But you would probably want to test that further before assuming that it is so. The Help screens did not say.

Link to comment
Share on other sites

What Bob said................................

 

I use that kind of indicator all the time for stuff. I usually annoy myself with them. In fact, I think they are tedious and inelegant, but they are very handy.

 

I probably use them where something different would probably work better, but this whole Macro Express thing is a constant learning experience.

 

Here's an example from a recent macro I tweaked.

 

I have a macro that processes huge text files, searching for specific information with in them. Sometimes the text files are hundreds of MBs in size, sometimes they are just a few KBs. To keep track of the huge ones, I had built some extra code to change/update a text box displaying the percentage of processes that had been completed (the big ones take 6-8 minutes), so that the user (usually me), can be confident that the macro really is still working.

 

Unfortunately, this extra code dramatically slowed down the small files. Overall time spent was negligible, but without the "updates" the small ones were done almost instantly, with the updates, the macro took 3-5 seconds. Not a big deal, but not really necessary.

 

So I considered options, and ended up building an initial indicator:

Set Variable %N10% to size of XYZ.txt.

If variable %N10% < 1000000

Set Variable %T8% to SKIP.

 

Then whenever the macro gets to the "update" section, I use:

If Variable %T8% <> SKIP

Update code

 

Of course, I could probably just us the "If variable N10 <1000000" code rather than set the %T8% to SKIP... But then, that's part of what annoys me :)

Link to comment
Share on other sites

Thanks for the follow-up, Steve.

 

I should get into the habit of using that sort of technique more often myself, as 'deferred decisions' seem to arise frequently in my macros.

 

It's been decades since I did any real programming (if you exclude a little BASIC on the BBC Micro and a brief flirtation with VBA in Excel years ago), but we used to call them 'flags' and test for their status with diamond-shaped elements in block diagrams.

;)

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...