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
>> >
>> >


.



Relevant Pages

  • RE: VB Code give unexplained answers.
    ... We changed the data type to data but still ... > You are not getting errors because Variant data types will accept anything. ... > Your comparisons are not working because you are not always comparing dates. ... >> Dim tmpAdjustment As Integer ...
    (microsoft.public.access.formscoding)
  • Re: Comparission cause problem
    ... >>Due to higher precision i would recommend to use the datatype double ... floating points then we should take the prefrence for the double data type. ... as you suggested that double will be faster as compared with the float. ... when it comes to comparing floating point types for equality you ...
    (alt.comp.lang.learn.c-cpp)
  • Re: NullPointerException vs = null check
    ... If one is better than the other, please set me straight. ... runtime exception is a lot more expensive than comparing a reference to ... Comparing a ref to null is very likely to be one of the most efficient ... but I also would not assume that there's no impact of an exception ...
    (comp.lang.java.programmer)
  • Re: glitch with variant data type parameters
    ... > values of different base data types are compared, ... > are in the same data type family, the value whose base data type is lower ... That's why the first query returns results. ... you are comparing an integer to a sql_variant with a ...
    (microsoft.public.sqlserver.programming)
  • Re: Thats it, Im getting a Sasquatch!
    ... a yard, not bad. ... is like comparing a glazed donut to a Boeing 747. ... hadn't swung a club in 3 months so I took it very easy. ... and I am anything but straight. ...
    (rec.sport.golf)