tedsmith said:
Sorry if I am a bit revolutionary
"Anachronistic" is the word that comes to mind. Before visual languages, programmers had to spend a lot of time writing code for the UI elements of their programs. A huge part of Visual Basic's popularity was due to the fact that being able to drop controls on a form and lay them out in design mode meant the programmer could concentrate a lot more on the business logic rather than the mechanics of the UI code. Your technique takes you back to the days when we had to write code to initialize the UI.
tedsmith said:
I update the database when the control loses focus
Quite simply that is a hugely unnecessary number of calls to the database. It makes the application unscaleable. As your user base grows, you will likely need to upgrade your server hardware and bandwith at a much greater rate then if you only updated once per record.
tedsmith said:
I don't like "update buttons" after a group of inputs as they can be forgotton
That's what IsDirty flags and "Do you want to save your changes?" prompts are for. Plus, you are not giving the user any chance to cancel their changes. What if the user has changed 5 fields and suddenly realizes they are updating the wrong record? They would have to update the same fields again, assuming they can even remember what the original values were.
tedsmith said:
The trick is use indexes as much as possible to make multiple use of the same subroutine. It cuts down the number of subroutines dramatically.
You seem to advocate that the less subroutines the better. In fact the number of subroutines has no relation to the maintainability of code. I follow the
Code Complete philosophy that subroutines should be highly specialized and do only one thing. Thus, 20 LostFocus events for 20 textboxes is better than one monolithic LostFocus event for all textboxes.
Code reuse is an important aspect of coding, but that is not the same as monolithic functions. If you want common validation for all textboxes, you should create one
ValidateText function and then pass in the text from each textbox's LostFocus event. That way you have a lean validation function without a whole bunch of Select Case statements that obscure its purpose.
tedsmith said:
You can also use the same form for many different tables
Uh oh, even more Select Case statements? Cause now I have to check the table name in addition to the controls index, don't I?
Your example of the 50 rich text boxes might be one where I would agree to use a control array, as I am assuming their behaviour is generic.
But your example of "Modify Client Details" is most definitely not a candidate for control arrays. Validating a phone number is different than a postal code or SIN number - which would require the use of those dreaded Select Case statements. This breaks the best code practice where a function should do only one specific thing.
Sorry if I seem to be beating up on you Ted, but I believe the OP was looking for advice on best practices, and your theories run counter to much of my own experience and learning.