RE: DateTime.Value.CompareTo in c#

  • From: "Andy B" <a_borka@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 26 Oct 2007 05:39:34 -0400

Hi...

I still get the same answer. The message box keeps showing up every tick...
Maybe I put this code in the wrong event... but I wouldnt know what one to
put it in...

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Martin Slack
Sent: Thursday, October 25, 2007 6:54 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: DateTime.Value.CompareTo in c#


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

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

Other related posts: