I’ll continue refactoring today, here’s where I ended up in yesterday’s message. It’s the main function that’s been split up into 1 helper function to test the Hash and make sure it’s available, otherwise display a message box. And a new class that holds information about the command string and returns some pertinent info about it.
So in the next section we start creating our variables and looping through the array of files to build the string:
So the main code executing here is an outer loop over all the files, then an inner loop that builds the string until it is either done, or trips the character limit of the PS_GetOutput function.
I’m looking for something simple here. We are manipulating the index of the array during the procedure using the internal loop mainly then backing the index down 1 and using that string if it trips the length trigger. So seems like I want a loop iterator object that could keep track of the array index. I think for simplicity, I’ll start with the little loop in the middle and write a function that will do the needed work. It would need to return the correct index to start the next segment of files as well as the string. Actually, if I just pass the index as a reference, I don’t have to pass any new value back to it. This isn’t valid compiling code yet, but just cutting and pasting the code into a new function:
I like that I’ve just pulled out a huge chunk of the original routine and now give it a much better name according to what it’s doing. Now let’s make it a valid function and place it appropriately in the original function I’m refactoring. I normally use retVal as function return values but in this case since sPathsPart is already the main thing we want to return, I’ll just use that so I don’t have to replace or rewrite those references.
And now it looks like I missed the LenCmd so I’ll add that into the variables, although I’m not sure I like adding a third parameter, but…
I’ll also need to Dim the sPreviousPart variable, but that should be it for variables needed and other than that, I just need to set the return value at the end.
Now our original function is much smaller and looks like this:
I think I can finish this up tomorrow for the original function. There would be more I’d want to refactor in the helper function I just created to make it a little more intuitive, but once I’m finished refactoring the original function, I’m going to end this series.
Trackbacks/Pingbacks