Re: DateTime.Value.CompareTo in c#

  • From: "Martin Slack" <m.g.slack@xxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 25 Oct 2007 23:54:18 +0100

Hi Andy,

I would guess that the "if" statement's expression is not being evaluated as you want. For instance, the Boolean ShowMsg will be set to true the first time the "if" statement itself is true. After that, the element of the expression !ShowMsg is obviously not being evaluated in the sense you require, since that is the part that should prevent all but the first showing of the message. I recommend putting the two sub expressions combined by the && operator in parentheses, like this:

if((!ShowMsg) && (DateTime.Now.CompareTo(Time.Value) > 0)) {

 hth

Martin


----- Original Message ----- From: "Andy B" <a_borka@xxxxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Thursday, October 25, 2007 12:19 PM
Subject: RE: DateTime.Value.CompareTo in c#


Hi Martin...

I have a .net 2.0 Timer object and the if statement is inside its Tick
event. The tick event fires every Timer.Interval (set at 1000) or every 1
second. So the code inside the Tick event runs every second. I tried doing
some code that looks like:

//make a flag saying if we shown the MessageBox yet.
bool ShowMsg=false; //haven't seen the box yet.

//if we haven't seen the box and the times are the same, show the box.
otherwise do nothing...
if(!ShowMsg && DateTime.Now.CompareTo(Time.Value)>0) {
//we will see the box so flag it true
ShowMsg=true;
MessageBox("timer went off");
}

This code got me what I wanted except the MessageBox actually popped up
every Tick (second) regardless of the ShowMsg being true or not. Any ideas?



---snip---

__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: