Simon Harriyott

Copy and paste coding

It's my last week of working here, which is strange. I'm working on odd little bits and pieces for people, which is understandable, but frustrating today. Today I'm working on some VBA code that is part of an iFix SCADA system. There are a series of button bars that correspond to the function keys. Depending on which screen is displayed, a different screen is opened from the button bar.

My instructions are to use the existing code, which has been written for the F1 key, and write code for the other eleven, "Only leave the format as it is, because the customer will be maintaining the code, and they won't be able to cope with constants and stuff".

So, there's one function for F1, another for F2, another for F3...

Each of these functions checks the name of the current screen, and the id (0, 1, 2 or 3) of the button bar, and then instructs iFix to open a different screen.

I would like to move this code into one function, and each of the Fx click events call this function with a parameter containing the function key. The [source screen -> Fx -> target screen] mappings could be kept in a separate file which could be read in; this would remove the need for recompiling and reinstalling when a screen changes.

However, I've been told that the customer wouldn't be able to understand this. They need to have all the code for the button in one place, so they can change it easily by selecting "Edit Code" from the actual button. I'm quite happy with the ideal of doing what the customer wants, and they are non-programmers, so it can't be hard. I still find it offensive to copy the same chunk of code into eleven other functions though.
19 October 2004