Converting nullable dates from vb6 to vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cathode Follower
    New Member
    • Feb 2008
    • 5

    Converting nullable dates from vb6 to vb.net

    In VB6 we put date values obtained from databases into variants. We can then use statements like IsNull(.EndDate ) to check whether a date is set or not. When you put code like this through the vb.net conversion wizard it turns out very messy and you have to make lots of changes by hand. The basic principle is that dates like this have to be represented as Nullable(Of Date) in vb.net.
    In order to make life simpler, I have introduced two simple procedures into the VB6 code:

    [CODE=vb]Public Function DateSet(ByVal InputDate As Variant) As Boolean
    DateSet = Not IsNull(InputDat e)
    End Function

    Public Function DateNotSet(ByVa l InputDate As Variant)
    DateNotSet = IsNull(InputDat e)
    End Function[/CODE]
    and have changed the vb6 code to use these procedures throughout. This also improves readability.

    In vb.net the corresponding procedures are:

    [CODE=vbnet]Public Function DateSet(ByVal Value As Nullable(Of Date)) As Boolean
    DateSet = Value.HasValue
    End Function[/CODE]
    and

    [CODE=vbnet]Public Function DateNotSet(ByVa l Value As Nullable(Of Date)) As Boolean
    DateNotSet = Not Value.HasValue
    End Function[/CODE]
    Last edited by Killer42; Feb 21 '08, 02:04 AM. Reason: Added CODE tags as appropriate
  • mafaisal
    New Member
    • Sep 2007
    • 142

    #2
    Hi,

    Use IsDBNull instead of IsNull

    Faisal


    Originally posted by Cathode Follower
    In VB6 we put date values obtained from databases into variants ...
    Last edited by Killer42; Feb 21 '08, 02:06 AM. Reason: Reduced excessive quote block

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Thanks for sharing, Cathode Follower. This sounds like useful stuff. It should be put in the Editor's Corner and developed into an article for the HowTo's section.

      Comment

      Working...