Using some sample code I was playing with in my last Refactoring article, we will see what RubberDuck does when reordering parameters. Here’s the code:
HAL_BasicEncryption
My TestFunction is where I will attempt to re-order parameters. Since I set some as optional, that could be an issue. If I try to put an Optional parameter in front of a required parameter, that would create an invalid parameter order.
Optional parameters must come at the end of the parameter list.
Let’s see what happens:


I will switch just Param1 and Param2 first. I suspect that will reverse the order in the function and also change the calling functions.
Here’s the new code:
That’s wonderful. Now I’ll try switching Param1 with Param3 and see what happens.

Nice! RubberDuck doesn’t activate the OK button and doesn’t let me do this. Let me try adding a default value for the optional parameter and see if it lets me reorder them then.

And RubberDuck still has the OK button deactivated. Which is the correct behavior because you must have optional parameters at the end of the list.
However, I should be able to swap the optional parameters. The dialog box allows me to do this and to hit the OK button and the window closes, however the parameters are not swapped. It appears that the optional parameters must all be used in every function call for the reorder to work, or they must be the last parameter. When I added the fourth parameter to the function call that was missing the fourth parameter, it worked and I ended up with this code:
Note that in the first TestFunction call, the empty 3rd parameter was removed and replaced with the fourth parameter, and the last comma was then dropped.