PC Review


Reply
Thread Tools Rate Thread

Advice on comparing time intervals

 
 
Ted
Guest
Posts: n/a
 
      2nd Mar 2005
I need to compare two time intervals in both military and Long time formats.
I have an application which needs to toggle the fore color of the time
display if the current system time is prior to >= to 8 pm toggle color red
else toggle color green. Can anyone provide me with some advice on how to
accomplish this. Here some sample code:

Select Case Me!optgrpTime.Value
Case 1
Me!txtSysClock.Format = "Long Time"
strCurTime = CStr(Me!txtSysClock)
If CDate(strCurTime) >= CDate("8:00:00 PM") Then
Me!txtSysClock.ForeColor = 255
Else
Me!txtSysClock.ForeColor = 32768
End If
Case 2
Me!txtSysClock.Format = "hh:mm:ss"
strCurTime = CStr(Format(Me!txtSysClock, "hh:mm:ss"))
If CDate(strCurTime) >= CDate("20:00:00") Then
Me!txtSysClock.ForeColor = 255
Else
Me!txtSysClock.ForeColor = 32768
End If
End Select


 
Reply With Quote
 
 
 
 
John Vinson
Guest
Posts: n/a
 
      3rd Mar 2005
On Wed, 2 Mar 2005 05:55:47 -0600, "Ted" <(E-Mail Removed)> wrote:

>I need to compare two time intervals in both military and Long time formats.
>I have an application which needs to toggle the fore color of the time
>display if the current system time is prior to >= to 8 pm toggle color red
>else toggle color green. Can anyone provide me with some advice on how to
>accomplish this. Here some sample code:
>
>Select Case Me!optgrpTime.Value
>Case 1
> Me!txtSysClock.Format = "Long Time"
> strCurTime = CStr(Me!txtSysClock)
> If CDate(strCurTime) >= CDate("8:00:00 PM") Then
> Me!txtSysClock.ForeColor = 255
> Else
> Me!txtSysClock.ForeColor = 32768
> End If
>Case 2
> Me!txtSysClock.Format = "hh:mm:ss"
> strCurTime = CStr(Format(Me!txtSysClock, "hh:mm:ss"))
> If CDate(strCurTime) >= CDate("20:00:00") Then
> Me!txtSysClock.ForeColor = 255
> Else
> Me!txtSysClock.ForeColor = 32768
> End If
>End Select
>


Wow. You're making it MUCH harder than it needs to be.

If Time() > #20:00# Then
Me!txtSysClock.ForeColor = vbRed
Else
ME!txtSysClock.ForeColor = vbGreen
End If

If you need to change the Format, remember that mm means the *Month* -
miNutes is "nn".

John W. Vinson[MVP]
 
Reply With Quote
 
Ted
Guest
Posts: n/a
 
      3rd Mar 2005
John,
Thanks but when I try to put your code snippet in the module, the value
#20:00# changes to #8:00:00 PM#.
Allow to explain more....there is an option group with two radial buttons
one labeled standard time and another labeled military time. Which ever
option the user chooses toggles the format property of a text box which
displays the current, which is updated using the timer event. When the time
is between 7:30 am and 8:00 pm, I want the time color green. When the time
is between 8:00 pm and 7:30 am I need the time color to be red. My issue
lyes in determining the time range..it could be militray comparison or
standard time comparison depending on the option choosen and the format set
by the user. I appreciate your help.

Ted


"John Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message
news:(E-Mail Removed)...
> On Wed, 2 Mar 2005 05:55:47 -0600, "Ted" <(E-Mail Removed)> wrote:
>
>>I need to compare two time intervals in both military and Long time
>>formats.
>>I have an application which needs to toggle the fore color of the time
>>display if the current system time is prior to >= to 8 pm toggle color red
>>else toggle color green. Can anyone provide me with some advice on how to
>>accomplish this. Here some sample code:
>>
>>Select Case Me!optgrpTime.Value
>>Case 1
>> Me!txtSysClock.Format = "Long Time"
>> strCurTime = CStr(Me!txtSysClock)
>> If CDate(strCurTime) >= CDate("8:00:00 PM") Then
>> Me!txtSysClock.ForeColor = 255
>> Else
>> Me!txtSysClock.ForeColor = 32768
>> End If
>>Case 2
>> Me!txtSysClock.Format = "hh:mm:ss"
>> strCurTime = CStr(Format(Me!txtSysClock, "hh:mm:ss"))
>> If CDate(strCurTime) >= CDate("20:00:00") Then
>> Me!txtSysClock.ForeColor = 255
>> Else
>> Me!txtSysClock.ForeColor = 32768
>> End If
>>End Select
>>

>
> Wow. You're making it MUCH harder than it needs to be.
>
> If Time() > #20:00# Then
> Me!txtSysClock.ForeColor = vbRed
> Else
> ME!txtSysClock.ForeColor = vbGreen
> End If
>
> If you need to change the Format, remember that mm means the *Month* -
> miNutes is "nn".
>
> John W. Vinson[MVP]



 
Reply With Quote
 
John Vinson
Guest
Posts: n/a
 
      3rd Mar 2005
On Wed, 2 Mar 2005 22:36:11 -0600, "Ted" <(E-Mail Removed)> wrote:

>John,
> Thanks but when I try to put your code snippet in the module, the value
>#20:00# changes to #8:00:00 PM#.


That is ABSOLUTELY IRRELEVANT.

THe value of #20:00# - what's actually stored in the table - is
0.83333333333333 (20/24 of a day). #8:00:00 PM# is another way of
depicting this time value. So is #8PM#.

>Allow to explain more....there is an option group with two radial buttons


"radio" buttons, from the old days when a car radio had five or six
station-select buttons, only one of which could be pushed.

>one labeled standard time and another labeled military time. Which ever
>option the user chooses toggles the format property of a text box which
>displays the current, which is updated using the timer event. When the time
>is between 7:30 am and 8:00 pm, I want the time color green. When the time
>is between 8:00 pm and 7:30 am I need the time color to be red. My issue
>lyes in determining the time range..it could be militray comparison or
>standard time comparison depending on the option choosen and the format set
>by the user. I appreciate your help.


You're mistaken. You're confusing data STORAGE with data DISPLAY. A
time value *is a time value* no matter how it's displayed. Your
previous post did not mention the time between midnight and 7:30;
given that additional constraint, try

If Time() >= #07:30# AND Time() < #08:00# Then
control.ForeColor = vbGreen
Else
control.ForeColor = vbRed
End If

John W. Vinson[MVP]
 
Reply With Quote
 
Ted
Guest
Posts: n/a
 
      3rd Mar 2005
Thanks gor the expanation John. I appreciate it.

ted
"John Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message
news:(E-Mail Removed)...
> On Wed, 2 Mar 2005 22:36:11 -0600, "Ted" <(E-Mail Removed)> wrote:
>
>>John,
>> Thanks but when I try to put your code snippet in the module, the
>> value
>>#20:00# changes to #8:00:00 PM#.

>
> That is ABSOLUTELY IRRELEVANT.
>
> THe value of #20:00# - what's actually stored in the table - is
> 0.83333333333333 (20/24 of a day). #8:00:00 PM# is another way of
> depicting this time value. So is #8PM#.
>
>>Allow to explain more....there is an option group with two radial buttons

>
> "radio" buttons, from the old days when a car radio had five or six
> station-select buttons, only one of which could be pushed.
>
>>one labeled standard time and another labeled military time. Which ever
>>option the user chooses toggles the format property of a text box which
>>displays the current, which is updated using the timer event. When the
>>time
>>is between 7:30 am and 8:00 pm, I want the time color green. When the time
>>is between 8:00 pm and 7:30 am I need the time color to be red. My issue
>>lyes in determining the time range..it could be militray comparison or
>>standard time comparison depending on the option choosen and the format
>>set
>>by the user. I appreciate your help.

>
> You're mistaken. You're confusing data STORAGE with data DISPLAY. A
> time value *is a time value* no matter how it's displayed. Your
> previous post did not mention the time between midnight and 7:30;
> given that additional constraint, try
>
> If Time() >= #07:30# AND Time() < #08:00# Then
> control.ForeColor = vbGreen
> Else
> control.ForeColor = vbRed
> End If
>
> John W. Vinson[MVP]



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
comparing time intervals znaya Microsoft Excel Worksheet Functions 0 8th May 2006 06:47 PM
A little advice on comparing cells systematic Microsoft Excel Programming 1 24th Dec 2005 11:20 AM
Comparing data intervals =?Utf-8?B?c21vdXRzYXQ=?= Microsoft Excel Discussion 4 8th Dec 2005 08:29 PM
time intervals Ed Weitz Microsoft Access Queries 2 15th Oct 2003 02:57 AM
asking advice in comparing ADP to VB application belgie Microsoft Access ADP SQL Server 2 3rd Oct 2003 07:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 AM.