+ Reply to Thread
Results 1 to 4 of 4

how to check that a var type date is initialized ??

  1. #1
    François
    Guest

    how to check that a var type date is initialized ??

    Let's suppose a declaration like this

    1. Set the static value

    Call LastInputDate(#08/15/2005#)

    2. Display the static value
    MsgBox(LastInputDate)

    Function LastInputDate (Optional dDate as date) as date
    Static dLastDate as Date

    If IsEmpty(dDate) then
    LastInputDate = dLAstDate
    Else
    dLastDate = dDate
    End Function.


    This is never working since dDate contains allways "12:00:00 Am". How to
    solve this ?

  2. #2
    Dave Peterson
    Guest

    Re: how to check that a var type date is initialized ??

    If you declare dLastDate as date, then it's initial value is 00:00:00.

    Could you check for that?

    Or you could declare it as a variant and continue to check using isempty().



    François wrote:
    >
    > Let's suppose a declaration like this
    >
    > 1. Set the static value
    >
    > Call LastInputDate(#08/15/2005#)
    >
    > 2. Display the static value
    > MsgBox(LastInputDate)
    >
    > Function LastInputDate (Optional dDate as date) as date
    > Static dLastDate as Date
    >
    > If IsEmpty(dDate) then
    > LastInputDate = dLAstDate
    > Else
    > dLastDate = dDate
    > End Function.
    >
    > This is never working since dDate contains allways "12:00:00 Am". How to
    > solve this ?


    --

    Dave Peterson

  3. #3
    Norman Jones
    Guest

    Re: how to check that a var type date is initialized ??

    Hi François'

    Try changing dDate to variant and using the IsMissing function.

    For example , the following worked for me:

    Sub InitialiseIt() '
    Call LastInputDate(#8/15/2005#)
    End Sub

    Sub DisplayIt()
    MsgBox (LastInputDate)
    End Sub

    Function LastInputDate(Optional dDate) As Date
    Static dLastDate As Date

    If IsMissing(dDate) Then
    LastInputDate = dLastDate
    Else
    dLastDate = dDate
    End If
    End Function


    ---
    Regards,
    Norman



    "François" <Franois@discussions.microsoft.com> wrote in message
    news:B78BBE10-9A49-4125-B388-AF4306F0554A@microsoft.com...
    > Let's suppose a declaration like this
    >
    > 1. Set the static value
    >
    > Call LastInputDate(#08/15/2005#)
    >
    > 2. Display the static value
    > MsgBox(LastInputDate)
    >
    > Function LastInputDate (Optional dDate as date) as date
    > Static dLastDate as Date
    >
    > If IsEmpty(dDate) then
    > LastInputDate = dLAstDate
    > Else
    > dLastDate = dDate
    > End Function.
    >
    >
    > This is never working since dDate contains allways "12:00:00 Am". How to
    > solve this ?




  4. #4
    Dave Peterson
    Guest

    Re: how to check that a var type date is initialized ??

    Oops. I confused dLastDate and dDate.

    Another way is to use a date that won't be used:

    Function LastInputDate(Optional dDate As Date = #12/31/9999#) As Date
    Static dLastDate As Variant

    If dDate = DateSerial(9999, 12, 31) Then
    ......



    Dave Peterson wrote:
    >
    > If you declare dLastDate as date, then it's initial value is 00:00:00.
    >
    > Could you check for that?
    >
    > Or you could declare it as a variant and continue to check using isempty().
    >
    > François wrote:
    > >
    > > Let's suppose a declaration like this
    > >
    > > 1. Set the static value
    > >
    > > Call LastInputDate(#08/15/2005#)
    > >
    > > 2. Display the static value
    > > MsgBox(LastInputDate)
    > >
    > > Function LastInputDate (Optional dDate as date) as date
    > > Static dLastDate as Date
    > >
    > > If IsEmpty(dDate) then
    > > LastInputDate = dLAstDate
    > > Else
    > > dLastDate = dDate
    > > End Function.
    > >
    > > This is never working since dDate contains allways "12:00:00 Am". How to
    > > solve this ?

    >
    > --
    >
    > Dave Peterson


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1