Optional date parameter initialization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Austin

    #1

    Optional date parameter initialization

    I am migrating my first vb6 app to vb.net 2003.

    In the vb6 app a number of subs had optional date parameters:
    Sub Fred ( ... ,optional FromDate as Date = 0...)

    I need something like zero in there to see if the parameter has been used or
    not.

    In vb.net the imported code fails with:
    Value of type 'Integer' cannot be converted to 'Date'

    I have to supply a default value for the date - is there anything I can use
    that obviously indicates that the parameter has not been supplied by the
    caller?

    --
    John Austin
  • Mattias Sjögren

    #2
    Re: Optional date parameter initialization

    [color=blue]
    >I have to supply a default value for the date - is there anything I can use
    >that obviously indicates that the parameter has not been supplied by the
    >caller?[/color]

    No, you either have to pick one date value to magically represent the
    missing state, or use method overloading.


    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Optional date parameter initialization

      "John Austin" <John.Austin@no spam.nospam> schrieb:[color=blue]
      > In the vb6 app a number of subs had optional date parameters:
      > Sub Fred ( ... ,optional FromDate as Date = 0...)
      >
      > I need something like zero in there to see if the parameter has been used
      > or
      > not.
      >
      > In vb.net the imported code fails with:
      > Value of type 'Integer' cannot be converted to 'Date'
      >
      > I have to supply a default value for the date - is there anything I can
      > use
      > that obviously indicates that the parameter has not been supplied by the
      > caller?[/color]

      I have recently written an article in German about supporting nullable date
      and time values. Maybe you'll find some of the code snippets useful:

      <URL:http://dotnet.mvps.org/dotnet/articles/nullabledates/>

      In VB.NET 'Nothing' referes to a value type's default value. Thus you can
      specify 'Nothing' as default value for the parameter. Note that this
      doesn't work with VB 2002/2003, but will be supported in VB 2005. In
      general I don't recommend to rely on a certain value to be interpreted as a
      null value.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Mattias Sjögren

        #4
        Re: Optional date parameter initialization

        [color=blue]
        >I have to supply a default value for the date - is there anything I can use
        >that obviously indicates that the parameter has not been supplied by the
        >caller?[/color]

        No, you either have to pick one date value to magically represent the
        missing state, or use method overloading.


        Mattias

        --
        Mattias Sjögren [MVP] mattias @ mvps.org
        http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
        Please reply only to the newsgroup.

        Comment

        • Terry Olsen

          #5
          Re: Optional date parameter initialization

          >[color=blue]
          > I have recently written an article in German about supporting nullable
          > date and time values. Maybe you'll find some of the code snippets useful:[/color]

          The online translators don't do a very good job of turning this into english
          :(


          Comment

          • John Austin

            #6
            Re: Optional date parameter initialization

            Yes MS have always had a blind spot with dates - a 'leaving date' in an
            employee record needs to be blank until they leave, but even with VB6 dates
            there was no equivalent of 'blank date' (which would map to NULL in SQL). I
            wish they would see the light!
            --
            John Austin


            "Herfried K. Wagner [MVP]" wrote:
            [color=blue]
            > "John Austin" <John.Austin@no spam.nospam> schrieb:[color=green]
            > > In the vb6 app a number of subs had optional date parameters:
            > > Sub Fred ( ... ,optional FromDate as Date = 0...)
            > >
            > > I need something like zero in there to see if the parameter has been used
            > > or
            > > not.
            > >
            > > In vb.net the imported code fails with:
            > > Value of type 'Integer' cannot be converted to 'Date'
            > >
            > > I have to supply a default value for the date - is there anything I can
            > > use
            > > that obviously indicates that the parameter has not been supplied by the
            > > caller?[/color]
            >
            > I have recently written an article in German about supporting nullable date
            > and time values. Maybe you'll find some of the code snippets useful:
            >
            > <URL:http://dotnet.mvps.org/dotnet/articles/nullabledates/>
            >
            > In VB.NET 'Nothing' referes to a value type's default value. Thus you can
            > specify 'Nothing' as default value for the parameter. Note that this
            > doesn't work with VB 2002/2003, but will be supported in VB 2005. In
            > general I don't recommend to rely on a certain value to be interpreted as a
            > null value.
            >
            > --
            > M S Herfried K. Wagner
            > M V P <URL:http://dotnet.mvps.org/>
            > V B <URL:http://classicvb.org/petition/>
            >
            >[/color]

            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: Optional date parameter initialization

              "John Austin" <John.Austin@no spam.nospam> schrieb:[color=blue]
              > Yes MS have always had a blind spot with dates - a 'leaving date' in an
              > employee record needs to be blank until they leave, but even with VB6
              > dates
              > there was no equivalent of 'blank date' (which would map to NULL in SQL).
              > I
              > wish they would see the light![/color]

              ..NET's 'SqlDateTime' supports null values even in current versions of
              ..NET... Maybe it's suitable in your scenario.

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://classicvb.org/petition/>

              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: Optional date parameter initialization

                "John Austin" <John.Austin@no spam.nospam> schrieb:[color=blue]
                > In the vb6 app a number of subs had optional date parameters:
                > Sub Fred ( ... ,optional FromDate as Date = 0...)
                >
                > I need something like zero in there to see if the parameter has been used
                > or
                > not.
                >
                > In vb.net the imported code fails with:
                > Value of type 'Integer' cannot be converted to 'Date'
                >
                > I have to supply a default value for the date - is there anything I can
                > use
                > that obviously indicates that the parameter has not been supplied by the
                > caller?[/color]

                I have recently written an article in German about supporting nullable date
                and time values. Maybe you'll find some of the code snippets useful:

                <URL:http://dotnet.mvps.org/dotnet/articles/nullabledates/>

                In VB.NET 'Nothing' referes to a value type's default value. Thus you can
                specify 'Nothing' as default value for the parameter. Note that this
                doesn't work with VB 2002/2003, but will be supported in VB 2005. In
                general I don't recommend to rely on a certain value to be interpreted as a
                null value.

                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://classicvb.org/petition/>

                Comment

                • Terry Olsen

                  #9
                  Re: Optional date parameter initialization

                  >[color=blue]
                  > I have recently written an article in German about supporting nullable
                  > date and time values. Maybe you'll find some of the code snippets useful:[/color]

                  The online translators don't do a very good job of turning this into english
                  :(


                  Comment

                  • John Austin

                    #10
                    Re: Optional date parameter initialization

                    Yes MS have always had a blind spot with dates - a 'leaving date' in an
                    employee record needs to be blank until they leave, but even with VB6 dates
                    there was no equivalent of 'blank date' (which would map to NULL in SQL). I
                    wish they would see the light!
                    --
                    John Austin


                    "Herfried K. Wagner [MVP]" wrote:
                    [color=blue]
                    > "John Austin" <John.Austin@no spam.nospam> schrieb:[color=green]
                    > > In the vb6 app a number of subs had optional date parameters:
                    > > Sub Fred ( ... ,optional FromDate as Date = 0...)
                    > >
                    > > I need something like zero in there to see if the parameter has been used
                    > > or
                    > > not.
                    > >
                    > > In vb.net the imported code fails with:
                    > > Value of type 'Integer' cannot be converted to 'Date'
                    > >
                    > > I have to supply a default value for the date - is there anything I can
                    > > use
                    > > that obviously indicates that the parameter has not been supplied by the
                    > > caller?[/color]
                    >
                    > I have recently written an article in German about supporting nullable date
                    > and time values. Maybe you'll find some of the code snippets useful:
                    >
                    > <URL:http://dotnet.mvps.org/dotnet/articles/nullabledates/>
                    >
                    > In VB.NET 'Nothing' referes to a value type's default value. Thus you can
                    > specify 'Nothing' as default value for the parameter. Note that this
                    > doesn't work with VB 2002/2003, but will be supported in VB 2005. In
                    > general I don't recommend to rely on a certain value to be interpreted as a
                    > null value.
                    >
                    > --
                    > M S Herfried K. Wagner
                    > M V P <URL:http://dotnet.mvps.org/>
                    > V B <URL:http://classicvb.org/petition/>
                    >
                    >[/color]

                    Comment

                    • Herfried K. Wagner [MVP]

                      #11
                      Re: Optional date parameter initialization

                      "John Austin" <John.Austin@no spam.nospam> schrieb:[color=blue]
                      > Yes MS have always had a blind spot with dates - a 'leaving date' in an
                      > employee record needs to be blank until they leave, but even with VB6
                      > dates
                      > there was no equivalent of 'blank date' (which would map to NULL in SQL).
                      > I
                      > wish they would see the light![/color]

                      ..NET's 'SqlDateTime' supports null values even in current versions of
                      ..NET... Maybe it's suitable in your scenario.

                      --
                      M S Herfried K. Wagner
                      M V P <URL:http://dotnet.mvps.org/>
                      V B <URL:http://classicvb.org/petition/>

                      Comment

                      Working...