Record changes in the variables
greet all the advice needed to do in C # record changes in a variable of type bool? variable value is read every 5 seconds and I need only record the change. from False to True andback. I thank Thomas
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Nov 29, 2011, 5:08 AM
bool? myBool = false;
bool? lastValue = false;
bool hasChanged = false;
private void timer1_Tick(object sender, EventArgs e)
{
if (myBool != lastValue)
{
lastValue = myBool;
hasChanged = true;
// possibly do something here
}
else
{
hasChanged = false;
}
}
Notice that a variable of type bool? can assume the values true, false or null.