In the event handler, I respond to a change in value. I have access to the old value and the new value and I want to do certain things depending on what the change is.
Each different result will perform some combination of actions / functions X, Y or Z. Z takes a parameter from -1 to 1. The order of these operations does not matter.
Look at the following logical grid. The old value is the leftmost column of labels, and the new value is the top row of labels:
New:
0 !=0
-------- -------
Old: 0 | nothing Y, Z(1)
What would be a good way to introduce this?
I work in C #, but I will accept answers in any language, since this is not a language issue - I can translate something.
Example:
if (oldvalue == 0 && newvalue == 0) return;
if (oldvalue != 0) X();
if (newvalue != 0) Y();
Z(oldvalue != 0 ? -1 : 0 + newvalue != 0 ? 1 : 0);
I suppose this looks good, but there are other ways to do it.
int which = (oldvalue == 0 ? 0 : 1) + (newvalue == 0 ? 0 : 2)
switch (which) {
case 1:
X(); Z(-1);
break;
case 2:
Y(); Z(1);
break;
case 3:
X(); Y();
break;
}
, , . , oldvalue newvalue , newvalue, 0.
. , , . , , .
, , , 2x2, . , "", , , X , oldvalue!= 0, , , , , , . , , , .
" ":
Conditions:
oldvalue == 0 ? 0 : 1
newvalue == 0 ? 0 : 2
Actions:
X = {false, true, false, true}
Y = {false, false, true, true}
Z(-1) = true where condition = 1
Z(1) = true where condition = 2
? .