Results 1 to 10 of 10

Thread: [RESOLVED] DateTime format validation method using DateTime.TryParse() always returns false??

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: DateTime format validation method using DateTime.TryParse() always returns false?

    If you're not going to do anything with the result of a .TryParse in VB.NET you can set the result to Nothing rather than creating a temporary variable you need to get rid of.
    Good call on that. Actually up until now I've never considered having Nothing as the return on a .TryParse(). Thanks!
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: DateTime format validation method using DateTime.TryParse() always returns false?

    Quote Originally Posted by DavesChillaxin View Post
    Good call on that. Actually up until now I've never considered having Nothing as the return on a .TryParse(). Thanks!
    It's not that you're using Nothing as the return. The return value is a Boolean regardless. The output parameter is a DateTime. If you pass Nothing to that parameter then, inside the TryParse method, it will receive the default value for the DateTime type, which is #1/01/0001#. If the conversion works then the method will assign the appropriate DateTime value to the parameter and that is what the method outputs. The only difference is that, because you used a literal rather than a variable, you don't have access to that output value.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width