terrypin Posted January 24, 2020 Report Share Posted January 24, 2020 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 Quote Link to comment Share on other sites More sharing options...
acantor Posted January 24, 2020 Report Share Posted January 24, 2020 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. Quote Link to comment Share on other sites More sharing options...
terrypin Posted January 24, 2020 Author Report Share Posted January 24, 2020 Thanks but no, pasting doesn't bring any variables across. Quote Link to comment Share on other sites More sharing options...
acantor Posted January 24, 2020 Report Share Posted January 24, 2020 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. Quote Link to comment Share on other sites More sharing options...
terrypin Posted January 24, 2020 Author Report Share Posted January 24, 2020 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? Quote Link to comment Share on other sites More sharing options...
Cory Posted January 25, 2020 Report Share Posted January 25, 2020 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. Quote Link to comment Share on other sites More sharing options...
acantor Posted January 26, 2020 Report Share Posted January 26, 2020 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: I uncheck "Prompt the user to create a variable that is not defined." Quote Link to comment Share on other sites More sharing options...
terrypin Posted January 26, 2020 Author Report Share Posted January 26, 2020 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: 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! Quote Link to comment Share on other sites More sharing options...
terrypin Posted January 26, 2020 Author Report Share Posted January 26, 2020 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted January 26, 2020 Report Share Posted January 26, 2020 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. 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.