Optional Date Parameter Bug! 
Author Message
 Optional Date Parameter Bug!

I have a function which, given 1 or 2 VB dates, creates a "between"
query for use with Oracle.
It accepts two date parameters, one optional:

Function sMakeRDODateQuery _
        (xStartDate As Date, Optional xEndDate As Date) As String
    Dim xEndDatePrivate As Date
    '
    ' If we only have start date, set the
    ' end date to the start date.
    '    
    If IsMissing(xEndDate) Then
        ' never gets executed!!!!
        xEndDatePrivate = xStartDate
    Else
        xEndDatePrivate = xEndDate
    End If
    '
    ' remaining code clipped
    '
End Function

If I only pass one parameter, like:

sQuery = sMakeRDODateQuery(Now)
The xEndDate parameter is passed as "12:00 AM", which becomes
Dec 30, 1899. The IsMissing function returns false.
If I change the xEndDate parameter to a variant, everything works as
expected.
What's up with that?

Dave
--
I am a resident of Washington state. In Washington, Spam
is subject to a $500 or greater penalty. You are warned.



Sun, 14 Jan 2001 03:00:00 GMT  
 Optional Date Parameter Bug!
Forget it- saw the post above.
Sorry.

Quote:

> I have a function which, given 1 or 2 VB dates, creates a "between"
> query for use with Oracle.
> It accepts two date parameters, one optional:

> Function sMakeRDODateQuery _
>         (xStartDate As Date, Optional xEndDate As Date) As String
>     Dim xEndDatePrivate As Date
>     '
>     ' If we only have start date, set the
>     ' end date to the start date.
>     '
>     If IsMissing(xEndDate) Then
>         ' never gets executed!!!!
>         xEndDatePrivate = xStartDate
>     Else
>         xEndDatePrivate = xEndDate
>     End If
>     '
>     ' remaining code clipped
>     '
> End Function

> If I only pass one parameter, like:

> sQuery = sMakeRDODateQuery(Now)
> The xEndDate parameter is passed as "12:00 AM", which becomes
> Dec 30, 1899. The IsMissing function returns false.
> If I change the xEndDate parameter to a variant, everything works as
> expected.
> What's up with that?

> Dave
> --
> I am a resident of Washington state. In Washington, Spam
> is subject to a $500 or greater penalty. You are warned.

--
I am a resident of Washington state. In Washington, Spam
is subject to a $500 or greater penalty. You are warned.


Sun, 14 Jan 2001 03:00:00 GMT  
 Optional Date Parameter Bug!
Yes unfort. it only works with variants !! (shit)


Quote:
>I have a function which, given 1 or 2 VB dates, creates a "between"
>query for use with Oracle.
>It accepts two date parameters, one optional:

>Function sMakeRDODateQuery _
> (xStartDate As Date, Optional xEndDate As Date) As String
>    Dim xEndDatePrivate As Date
>    '
>    ' If we only have start date, set the
>    ' end date to the start date.
>    '
>    If IsMissing(xEndDate) Then
> ' never gets executed!!!!
>        xEndDatePrivate = xStartDate
>    Else
>        xEndDatePrivate = xEndDate
>    End If
>    '
>    ' remaining code clipped
>    '
>End Function

>If I only pass one parameter, like:

>sQuery = sMakeRDODateQuery(Now)
>The xEndDate parameter is passed as "12:00 AM", which becomes
>Dec 30, 1899. The IsMissing function returns false.
>If I change the xEndDate parameter to a variant, everything works as
>expected.
>What's up with that?

>Dave
>--
>I am a resident of Washington state. In Washington, Spam
>is subject to a $500 or greater penalty. You are warned.



Sun, 14 Jan 2001 03:00:00 GMT  
 Optional Date Parameter Bug!
Definition of IsMissing function from VB Reference:
"Returns a Boolean value indicating whether an optional __Variant__ argument
has been passed to a procedure."

set a default value for the optional argument to be Null then use IsNull to
test it.  Null means no valid data.

Leen



Sun, 14 Jan 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Optional Date Parameters

2. Using Parameter Queries with Optional Parameters

3. passing optional parameters to the parameters collection

4. VB-Bug ---->argument not optional

5. RegExp Bug: Negative Lookahead Following Optional Character

6. Writing A Function with optional parameters

7. how to declare a function with optional parameters

8. > passing vb6 optional byref parameter into c#

9. how to make array an optional parameter

10. Function overloading and Optional parameters

11. Inheritance across VB assemblies: Optional parameter compiler problem

12. Default value in optional parameter

 

 
Powered by phpBB® Forum Software