top of page

Add / remove / re-order parameters ... and update corresponding arguments

John

VBE_Extras can now help you to add, remove and re-order parameters for a Sub, Function or Property (I'm just gonna say "procedure" from now on ... all of the commands described in this post work on Subs, Functions and Properties). When it does this, it doesn't only update the signature of the procedure itself but it also updates all calls of (i.e. references of) the procedure at the same time i.e. arguments are added / removed / re-ordered as required.


Additionally, if you want to promote an existing variable within a procedure to be a parameter then VBE_Extras can help with that ... and if you want to demote an existing parameter of a procedure to be a variable then it can help with that also.


Add parameter

 

Add a parameter to a procedure and simultaneously add an argument for all references of that procedure.

 

  • For the arguments added for the references of the procedure – normally positional arguments will be used, named arguments will be used if a reference already uses one or more named arguments AND if the new argument comes after that named argument

  • In the 'Add Parameter' dialog, only very limited validation is carried out for the 'Default value' for Optional parameters and for the 'Value to inject at call site(s)' ... and the validation that is carried out for both of these can always be overridden

  • If the host application is Excel:

    • If the procedure is 'assigned as a macro' to a Shape then adding a 'required' parameter will break the link from the Shape ... a warning will be shown if this is the case

    • If the procedure is the target of a keyboard shortcut then adding either a 'required' or an Optional parameter will break the keyboard shortcut ... a warning will be shown if this is the case


The 'add parameter' dialog

 

Promote local variable to parameter

 

Promote a local variable within a procedure to be a parameter of that same procedure and simultaneously add an argument for all references of that procedure or Property.

 

  • Only variables can be promoted: not Statics, Consts

  • If the variable is an array, it must be 'dynamic' not 'static' (i.e. it must not be defined with explicit bounds)

 

The 'promote parameter' dialog

Remove parameter

 

Remove a parameter from a procedure and simultaneously remove the matching argument from all references of that procedure.


The 'remove parameter' dialog

Demote parameter to local variable

 

Remove a parameter from a procedure and make it a local variable within that same procedure and simultaneously remove the matching argument from all references of that procedure.

 

  • Demoting always creates a Dim statement (never a Static or Const)


The 'demote parameter' dialog

Reorder parameters

 

Reorder one or more parameters of a procedure and simultaneously reorder the matching arguments of all references of that procedure.

 

  • A ParamArray parameter cannot be reordered (it must be the last parameter)

  • The value/reference parameter of a Property Let/Set cannot be reordered (it must be the last parameter)

  • Parameters can/must be updated from being 'required' to being 'Optional', and vice-versa, depending on the parameter order


The 'reorder parameters' dialog

Each of these commands ...


  • Correctly handles matching Properties (i.e. any matching Get / Let / Set will also be updated)

  • Correctly handles both positional and named arguments

  • Correctly handles required, Optional and ParamArray parameters including (for Optional and ParamArray) omitted arguments and arguments that are provided as an 'empty comma'

  • Will preserve any existing Attributes


To learn more on each of these commands, check out the 'Update parameters' section of the VBE_Extras user guide.


And to give it a try (VBE_Extras currently comes with a 60 day free trial), see the Download VBE_Extras page.

0 comments

Recent Posts

See All
bottom of page