Jump to content
Macro Express Forums

Best Practice For Using Macros As Subroutines?


Cory
 Share

Recommended Posts

I'm getting to the point where I could benefit by calling some subroutines instead of rewriting them all the time and was hoping for some advice on how best to handle variables.

 

Obviously var’s in the parent pass to the called macro but if I write a macro today to be a sub I can’t anticipate what the best var’ would be to use. I see the var save/restore and I think that is key but how should one use it? I can think of a couple of ways but I was hoping I could benefit from some old hands experience as to the best way. My thought was to do a save before and a restore after the call with a transition var save as an adapter but if the sub was returning a var the restore would overwrite it. I know there must be an easy way to do this so any help would be greatly appreciated.

 

Thank you all!

Link to comment
Share on other sites

hi, Cory,

 

I would also be interested in this.

 

1. I know there is a facility in PGMacro library for this (layers of variable usage), and maybe Floyd can explain that. I have not used it yet.

 

2. where I am repeatedly calling routines, and self- calling recursing multiple times, and have this problem, is obviously in my home-made "MEBasic". I usually have only a few "parameters" (1-4, say), and an "Answer" at the end, so I do a full "Save" at the beginning , once only, then "Restore" after each recursion or sub, and save any required vars as environment vars (eg "Parameter1", and "AnswerString".

 

I think it is not perfect, but the naming is easy, and after each I only have to retrieve "AnswerString". and however many other variables, by number and parameter name, that i know should be returned.

 

I'll be interested to see what you come up with.

 

Best, Randall

Link to comment
Share on other sites

As far as the Save and Restore Variables in PGM Library are concerned, we've effectively extended the number of sets of variables that can be addressed to 16. Thus you could do up to 16 Variable Saves (nested), and the same number of Variable Restores, and it would all work.

 

As far as ME is concerned there are only 2 sets of variables, the ones you are currently working with and the ones you saved when you did a Variables Save command.

 

As far as subroutines are concerned, both Joe and I tend to use variables 1 to 10 (and sometimes 1 to 20) as "temporary" variables - by this I mean that in any subroutine I can readily change these variables as I "know" that none of the higher-level macros have stored anything important in these (and by "know", I'm simply referring to our own internal standards).

 

But, most important, write remarks in each macro to document which variables are used and for what purpose.

Link to comment
Share on other sites

Hi, Cory,

 

calling some subroutines

 

I wonder if you would be interested in adding any subroutines to the MEBasic set of UDFs I have been putting together?

 

The aim is;

1. Add simple re-callable UDFs to ME.

2. Make them simple to write with the Wizard.

3. "demo" therefore what we would like in ME itself (and/or PGMmacros)

 

As you know, it is buggy (less so as time goes on, despite your experience!) and a private set of UDFs. Each macro just needs to be a sub-routine with certain parameters input to start, and certain others output at the end.

 

I have just got going some other ones not in the posted form; Excel com read/ write/ add to cell; Folder picker starting at a given directory, and others. I have dates working for any input I have been able to imagine, (including Region- appropriate), and checking now to avoid crashes. I am planning File Write Date stamp and others.

 

I am especially interested in getting some com for other Office suites, but do not know Outlook command lines etc which you seem to do, and I have not used email subroutines at all in ME.

 

Best, Randall

(Same invitation to any others with sub-routines out there!)

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...
 Share

×
×
  • Create New...