Results 1 to 14 of 14

Thread: Using VB 6 functions in .net

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Using VB 6 functions in .net

    Hello everyone!

    I am looking for a way to access the vb 6 version of IsDate(). The .net version under microsoft.visualbasic.isdate is just a wrapper for datetime.parse(). Usually the .net version works fine if the data you pass it is already suposed to be a date and you are just verifying it. If the expression passed is not a date an exception is thrown. Exceptions are slow, at least slow enough that I can't run the function back to back 30 plus times without it taking 60 seconds or so, in vb 6 it takes less than a second.

    So what I need is a way to use the function that VB6 calls, not the .net wrapper. I could make a COM object with just that function inside but I am trying to make a 100% .net project and using COM would violate that. I know calling VB6 directly IS using COM, but atleast I don't have to worry about installing my cheap little IsDate class.

    In the end I am trying to write a class that will go through plain text and pick out any dates, if anyone has any suggestion I am all ears.

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Using VB 6 functions in .net

    Use regular expressions. That is a .NET way. Regex class can be found in System.Text.RegularExpressions namespace.

    You can use this Regular Expression to validate the date
    VB Code:
    1. MessageBox.Show(System.Text.RegularExpressions.Regex.IsMatch("12-12-2005", "((([0][1-9]|[12][\d])|[3][01])[-/]([0][13578]|[1][02])[-/][1-9]\d\d\d)|((([0][1-9]|[12][\d])|[3][0])[-/]([0][13456789]|[1][012])[-/][1-9]\d\d\d)|(([0][1-9]|[12][\d])[-/][0][2][-/][1-9]\d([02468][048]|[13579][26]))|(([0][1-9]|[12][0-8])[-/][0][2][-/][1-9]\d\d\d)"))
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Re: Using VB 6 functions in .net

    Shuja Ali

    I tried that, I found that same snipet of code elsewhere and it didn't work on the following format "April 28, 1992". I understand why it didn't work and I wish I could fix it but I don't know how to write regular expressions.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Using VB 6 functions in .net

    soo.... why not re-format it for purposes of the function?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Re: Using VB 6 functions in .net

    I don't know how hard it is to write regular expressions and concidering the scope of the project speding a lot of time writing the regular expression may not be worth it compared to having to carry around a COM component.

    I was hoping it would be as easy as referencing some VB 6 dll that would contain the VB 6 IsDate function.

  6. #6
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Using VB 6 functions in .net

    Quote Originally Posted by NeoGioZ
    I don't know how hard it is to write regular expressions and concidering the scope of the project speding a lot of time writing the regular expression may not be worth it compared to having to carry around a COM component.

    I was hoping it would be as easy as referencing some VB 6 dll that would contain the VB 6 IsDate function.
    I would still suggest either using the Regular Expressions or use the ParseExact method of DateTime Class.

    If you use IsDate function, you might have to change it finally down the lane. Because you never when MS will remove VB namespace from .NET.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Using VB 6 functions in .net

    Quote Originally Posted by NeoGioZ
    I don't know how hard it is to write regular expressions and concidering the scope of the project speding a lot of time writing the regular expression may not be worth it compared to having to carry around a COM component.

    I was hoping it would be as easy as referencing some VB 6 dll that would contain the VB 6 IsDate function.
    Odds are you're not the first person to need this... there's plenty of resources out there (this place being one of them) where you can get a canned regex. I still don't see why you can't format it and pass it to the regex.... but what ever.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Re: Using VB 6 functions in .net

    Quote Originally Posted by techgnome
    Odds are you're not the first person to need this... there's plenty of resources out there (this place being one of them) where you can get a canned regex. I still don't see why you can't format it and pass it to the regex.... but what ever.

    -tg
    I can't preformat because I am reading through plain text, legal jargon to be exact, and out of a whole paragraph of text I need to pick out one or two dates that could be in any format acceptable in U.S English.

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Re: Using VB 6 functions in .net

    Quote Originally Posted by Shuja Ali
    I would still suggest either using the Regular Expressions or use the ParseExact method of DateTime Class.

    If you use IsDate function, you might have to change it finally down the lane. Because you never when MS will remove VB namespace from .NET.
    Thank you for your replies everyone , man this is a though one...

    I can't use ParseExact because it's too slow, I need to run through 30+ words and pick out a date or two out of legal jargon, all that needs to happen in a second or two. My old VB 6 code does it in under a second.

    Does anyone know of a good regular expressions tutorial? I might have to give in and learn regular expressions.

    on the vb namespace...

    Each version of .net is supposed to include the previous version inside it. By design my code can only run in the .net framework and since every version will encompass the previous version I am guaranteed that the vb namespace will always be there. Microsoft even recomends using the vb namespace if you know what your looking for because it save coding time by not having to figure out the .net way.

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

    Re: Using VB 6 functions in .net

    You haven't said what version of VB.NET you're using. If it's 2005 then use Date.TryParse.
    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

  11. #11

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Re: Using VB 6 functions in .net

    Quote Originally Posted by jmcilhinney
    You haven't said what version of VB.NET you're using. If it's 2005 then use Date.TryParse.
    I am .net 1.1 (vs 2003). Thanks.

  12. #12
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: Using VB 6 functions in .net

    then just simulate the tryparse like this

    VB Code:
    1. Dim dt As Date
    2. Try
    3.   dt = Date.Parse("23 April Watevaaa...")
    4. Catch
    5.   'code for if string was not a valid date
    6. End Try

  13. #13

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Re: Using VB 6 functions in .net

    Quote Originally Posted by Phill64
    then just simulate the tryparse like this

    VB Code:
    1. Dim dt As Date
    2. Try
    3.   dt = Date.Parse("23 April Watevaaa...")
    4. Catch
    5.   'code for if string was not a valid date
    6. End Try
    That is the problem, date.parse is very slow in .net 1.1 if the value passed is not a date. Try it with a odd string and see how long it takes to return an exception.

    BTW, Date.TryParse in .net 2.0 works great! Now I need to convience my boss to fork out the cash.

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

    Re: Using VB 6 functions in .net

    As an aside, Double.TryParse was originally created because IsNumeric had the same issue that you are experiencing with IsDate. IsNumeric was reimplemented to use Double.TryParse, so I'd guess that in .NET 2.0 IsDate has been reimplemented to use Date.TryParse. That still doesn't mean that it's a good idea to use the Runtime functions. You lose nothing if you don't need to keep the parsed value but if you do then you'll end up parsing it twice; once in the IsNumeric or IsDate function to check whether it's valid, then again to actually get the value.

    I guess what you could do is use a tool to look inside the Date.TryParse method and then create your own method that works the same way in .NET 1.1. I've never used it but I believe that Reflector is a useful tool for this. You may also like to get some of the other useful tools from that page.
    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

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