With the new set of functions that I’ve refactored last time, I’m going to update the other functions to use them. So let’s go back to the first 3 counting tests and use the dictionary creation function to make them more readable.
Here they are now:
The change won’t result in less lines, but it will result in the assignment of the dictionary being obvious about the arguments purposes:
I had to update the helper functions to support passing null values by changing the variable types to Variant and defaulting them to Null.
Now let’s take the other Verify Changes test and refactor that to use the new functions. Here it is before:
And the resulting refactor is:
All right, not too shabby. Took a little longer than I thought, but now to write some new tests for different types of fields to test their values should be pretty easy. We’ll start on that in the next session.
Before I finish though, I’d just like to point out that I have been using a feature of VBA that allows you to pass parameters to functions by specifying the parameter by the name used in the function. As you can see in the above code, you just enter the parameter name with a := and then the value you want to pass. In this way, it makes it very clear in the code what the function parameters are doing. I made both the InitialValue and ChangeTo parameters optional so that we don’t have to pass dummy values when we just want either an initial value only or a change to value only.
See you soon…