Re: VB Code give unexplained answers.



> If the log in time equals 08/09/05 10:30:00 the first
> test which is "Is this less than or equal to 11:00:00AM" fails and skips
> straight to the else which is wrong.


Nope, that's actually correct. It just isn't what you want. :-)

Date values include Date (whole number) and Time (decimal) information. Your
current comparison can be restated as:
#08/09/05 10:30:00 AM# < #12/31/1899 11:00 AM#
which is false. (0 = 12/31/1899, 1 = 1/1/1900, etc.)

The TimeValue function returns just the time portion of an expression (well,
sort of, it reduces the date portion to zero).
The following returns True:
TimeValue(#08/09/05 10:30:00 AM#) < #12/31/1899 11:00 AM#

HTH,
--
George Nicholson

Remove 'Junk' from return address.
"gdonald20" <gdonald20@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:30628204-6EC1-467B-B537-3EE2C7D46D53@xxxxxxxxxxxxxxxx
> Hi
>
> Thanks very much for you help. We changed the data type to data but still
> this code doesn't work.
>
> I have run the code in debug mode and looked at each value held by the
> current line of code. If the log in time equals 08/09/05 10:30:00 the
> first
> test which is "Is this less than or equal to 11:00:00AM" fails and skips
> straight to the else which is wrong.
>
> Then at the next test comparing the log out which is now(), the data shows
> as 15:00:00 which should clearly prove the stsament false and set the
> adjustment to 0 but i always sets the adjustment to 10.
>
> Can't see at all what is causing this.
>
>
> "Klatuu" wrote:
>
>> Here you are assigning tmpLog_In_Time a text value, not a time.
>> tmpLog_In_Time = _
>> Forms!frmFactory_Menu!fsubFactory_Menu!txtLast_Live_Log_In
>>
>> You have defined all your variables where you are manipulating time as
>> Variant. They should be Date.
>> You are not getting errors because Variant data types will accept
>> anything.
>> Your comparisons are not working because you are not always comparing
>> dates.
>>
>>
>> "gdonald20" wrote:
>>
>> > Hi
>> >
>> > I have attached below some VB code i am using on the on click property
>> > of a
>> > button on one of my database forms.
>> >
>> > When i run the code and compare it against the log in and log out times
>> > it
>> > gives me the wrong answers. For example if the log in time was before
>> > 11:00am
>> > and the log out was before 17:00 the field tmpadjusment should be 10
>> > but the
>> > code keeps skipping straight through to the else.
>> >
>> > Dim tmpLog_In_Time, tmpLog_Out_Time As Variant
>> > Dim tmpAdjustment As Integer
>> > Dim tmpLogging_Out As Boolean
>> >
>> > tmpLog_In_Time =
>> > Forms!frmFactory_Menu!fsubFactory_Menu!txtLast_Live_Log_In
>> > tmpLog_Out_Time = Now()
>> >
>> > tmpLogging_Out =
>> > Forms!frmFactory_Menu!fsubFactory_Menu!txtLog_In_Status
>> >
>> > DoCmd.Echo False
>> > DoCmd.SetWarnings False
>> >
>> > ' If Forms!frmFactory_Menu!fsubFactory_Menu!txtLog_In_Status Then
>> > If tmpLogging_Out Then
>> >
>> > tmpAdjustment = 0
>> >
>> > ' The person is now logging out
>> >
>> > If tmpLog_In_Time <= #11:00:00 AM# Then
>> >
>> > If tmpLog_Out_Time > #5:00:00 PM# Then
>> >
>> > tmpAdjustment = 20
>> >
>> > Else
>> >
>> > tmpAdjustment = 10
>> >
>> > End If
>> >
>> > Else
>> >
>> > If tmpLog_Out_Time > #5:00:00 PM# Then
>> >
>> > tmpAdjustment = 10
>> >
>> > Else
>> >
>> > tmpAdjustment = 0
>> >
>> > End If
>> > End If
>> >
>> > I would appreciate any help.
>> >
>> > Thanks
>> >
>> >


.