On 18/07/2010 22:07, Dave Unger wrote:
> Hello Harald,
>
> On Jul 18, 12:18 pm, "Harald Staff"<nos...@not.invalid> wrote:
>> You did not understand my response.
>
> Yes, I did. I do understand what you’re saying about flow, decisions,
> action, and I’m accepting that as good advice. I think we’re talking
> at cross purposes here.
>
>> You have "If Param1" in both procedures and "Hilite"
>> in the same two.
>
> In this simple example it almost has to be that way. Sub
> AnswerQuestion is checking each answer as it is entered - if incorrect
> AND Param1 = “A”, it hilites it in red. Later, when all the questions
> are answered, sub Main also checks Param1, if = “B”, then hilites all
> incorrect answers in red. So, dependant on Param1 value, either the
> incorrect answers are hilited in real time, or, hilited all at once,
> after completion.
See how much of the validity checking you can do using lists of valid
parameters and then separate out the residual checking of the worksheet
entries for validity entirely from whatever the processing action code
for the sheet does. Having spaghetti with no clear logic overview is a
recipe for trouble.
It seems like you need to split the code into CheckAnswersValid perhaps
with a parameter to tell it which parameter changed most recently for
the realtime check and which can then be reused in the Main action code.
>
> As we’re using Param1 at 2 different times, to do 2 different things,
> it’s almost impossible to keep all the flow, decisions, and action
> together. And yes, this example could be constructed more sensibly,
> but in the “real” application these 2 procedures could be miles apart.
You should only ever have one routine for checking the inputs are valid!
>
> Maybe part of the problem is, there should be 2 separate parameters,
> each with a value =true/false, not 1 parameter with multiple values
> (which is what the client is wanting). I’ll have to go back to the
> drawing board with some of this.
That doesn't alter things much. If anything it is better to have the
input parameters that reflect how the *user* thinks of things.
Box is small/medium/large/extralarge with a 4 way case statement makes
a lot more sense to user and programmer and is easier to maintain than
nested if statements.
>
> Thanks very much for your expertise and replies, much appreciated.
If there is a McCabes CCI routine available for VBA then you might want
to give it a try to find out where the maintenance traps are residing in
this codebase.
Regards,
Martin Brown
|