Jump to content
Macro Express Forums
terrypin

Removing unwanted variables

Recommended Posts

I'm in the middle of a complex macro which has many sub-macros (some with sub-macros themselves). About 25 macros in total. My scripting has been a tad impatient and one consequence is that I now have about 60 variables of which maybe half are superfluous. Anyone with ideas on a fast way to isolate the redundant ones please? I could then confidently delete them from all macros in which they currently appear in the variables list. (Or maybe have a fun digression doing that with a macro.)

 

The best I can think of is to run a  macro to clear all 60 variables, run the main macro and all its sub-macros, then run a macro to display all variables, making the assumption that any which are still empty are redundant.

 

With time zones in mind I'll probably try that shortly and report back promptly if it works OK.

 

Friday 24 January 2020, 0955 UK GMT

 

Share this post


Link to post
Share on other sites

Might it work to copy the entire script, and paste the code into a new script? I assume the variables in use would come along for the ride, but not the extra ones.

Share this post


Link to post
Share on other sites

Hi Terry,

 

I just tested, and it worked for me.

 

I made a new macro, created six text variables, deleted four lines that contained four variables. Then...

 

1. I selected the entire script in the Script Editor.

2. I copied it.

3. Closed the Script Editor.

4. Created a new macro.

5. Pasted the old script into the Script Editor.

 

In the new macro, I checked the Variables page, and only the two text variables that I had not deleted were there.

Share this post


Link to post
Share on other sites

Thanks for testing Alan. I'm guessing that you're taking an extra step that I didn't: after step 5 are you stepping through your macro in response to successive messages that the variables mentioned don't exist,  and allowing their assignment? In my case that takes a while but after dinner I'll do so and then:

1. See if the macro still runs

2. Compare the old and new variable list

 

I'm also hazy about the many variables being used within my submacros.

 

Directly after step 5 did you, like me, initially see on the variables page of the fresh macro only the standard 'T', 'N', etc?

 

Share this post


Link to post
Share on other sites

I don't understand exactly, but I think I'd export to text and grab all the variables using RegEx. Make a unique list for each macro. Them it should be obvious which are needed.

Share this post


Link to post
Share on other sites

Not sure if this MEP setting simplifies the process, but I'll put it out there. Years ago, I unchecked this checkbox, and haven't missed the extra prompt every time I create a variable. MEP almost always correctly guesses the type of variable:

 

image.png.3f1d26db1f16bd99157ff429892303fe.png

 

I uncheck "Prompt the user to create a variable that is not defined."

Share this post


Link to post
Share on other sites

Thanks 

2 hours ago, acantor said:

Not sure if this MEP setting simplifies the process, but I'll put it out there. Years ago, I unchecked this checkbox, and haven't missed the extra prompt every time I create a variable. MEP almost always correctly guesses the type of variable:

 

image.png.3f1d26db1f16bd99157ff429892303fe.png

 

I uncheck "Prompt the user to create a variable that is not defined."


Thanks Alan. I’ve always found that handy myself but I’ll see if unchecking makes the subject task any easier.

 

When developing a complex macro like this one, it’s useful that when routinely saving it MEP pops up a series of warnings and tapping Y to each very quickly gets the undefined variables setup.

 

BTW, I can’t test the following right now (posting from my iPad), but I think I’m right that I can confine my task to the main macro? IOW, even if all the many of the submacros it calls have their necessary variables defined (as well as unnecessary ones), the main macro must also have these defined too?

 

Anyway, I’ve decided to postpone this ‘housekeeping’ until the entire project is finished!

Share this post


Link to post
Share on other sites
8 hours ago, Cory said:

I don't understand exactly, but I think I'd export to text and grab all the variables using RegEx. Make a unique list for each macro. Them it should be obvious which are needed.


Thanks Cory, interesting idea. As per my reply to Alan, I’ve decided to tolerate the untidiness until the project is completely finished. 

Share this post


Link to post
Share on other sites

You're welcome. Also there are some online RegEx debuggers for free like this one which I have not tried yet. I use a Windows program RegEx Buddy which I recommend. If you ever want to play with some. 

Share this post


Link to post
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...