Link to home
Start Free TrialLog in
Avatar of luca345
luca345

asked on

DateDiff VB6 function equivalent Vb.net

Hi ,

I have try the create and exact equivalent of old DateDiff in VB.net but not work:

//

    Const DATE_YEAR = "yyyy"  
    Const DATE_QUARTER = "q"      
    Const DATE_MONTH = "m"      
    Const DATE_DAY_OF_YEAR = "y"  
    Const DATE_DAY = "d"          
    Const DATE_WEEKDAY = "w"    
    Const DATE_WEEK = "ww"      
    Const DATE_HOUR = "h"      
    Const DATE_MINUTES = "n"    
    Const DATE_SECONDS = "s"      

    Public Function S_DateDiff(Interval As String, Date1 As Date, Date2 As Date) As Integer

        Dim TmpDateStart As DateTime = Date1
        Dim TmpDateEnd As DateTime = Date2

        Dim DateDifference As TimeSpan = TmpDateEnd.Subtract(TmpDateStart)

        Dim LInterval As String

        LInterval = Lcase(Interval)

        Select Case LInterval

            Case DATE_DAY, "4"
                Return DateDifference.Days

            Case DATE_WEEK, "6"
                Return DateDifference.Days * 7

            Case DATE_HOUR, "7"

                MsgBox(DateDiff(Interval, Date1, Date2))

                Return DateDifference.Hours

            Case DATE_MINUTES, "8"
                Return DateDifference.Minutes

            Case DATE_SECONDS, "9"
                Return DateDifference.Seconds

            Case Else
                Return ""

        End Select

//

When I pass the "h" interval (hour) this function return a different value of the original VB6 function.

Someone can help me to fix this problem ?

Thank you
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of luca345
luca345

ASKER

Thank you !

I need in Vb.net an exact clone (new function) of the old Vb6 "format" function.

If I post this thread are you interested ?
You have posted a few of these requests for VB6 clones, and I wonder why you are spending time on that. Is it a school exercise? Then it is a good one.

Otherwise, why are you spending time on such a useless endeavour?

I understand that you are not allowed to use the old VB6 functions in your code. And personnally, I feel that this is the right way to do things. It eases the transition and exchange of information between languages and goes directly to the framework instead of going through an intermediary, improving performance.

And except for a few exceptions, the .NET functions that replace the old one are always easier to use and understand, and are better most of the time.

So why no simply use the ones provided by .NET?

If it is a question of copying old VB6 codes to .NET because you find that the converter does not does a good job, then you are losing your time. The converter does as good a job as it can. The problem of converting a VB6 appliction to .NET is not a problem of syntax, it is a problem of design. Applications in .NET are not designed the same way as they were in VB6 because the framework does not answer to the same rules.

Any type of direct conversion will end up being a maintenance nightmare with very bad performance. Trying to do better than the people who made the converter won't solve any problem, it risks being worse because you might not understand the challenge as well as they did.

Most of the time, rewriting an application in .NET instead of trying to convert it ends up taking less time while giving you applications with a better performance and easier maintenance. And this, now matter what you use to make the conversion.
Avatar of luca345

ASKER

Hi JamesBurger ,

4 month ago I was start to convert a VB6 project to VB.net.

1 month ago I was finish, but the new .NET project contain 30/40% of VB6 functions.

Now the some project contain only 2 VB6 old instructions:

1) Api 'GetWindowThreadProcessId'
2) 'Format'

I need to find a clone of 'Format' function and a way to replace the 'GetWindowThreadProcessId' Api.

When I will do it the project is 100% pure VB.net , no api no win32 calls.

And after I can convert it to C# and then I can import this to monoproject and the application can run to all platform (win , mac , linux)

In all of this step I learn many thing.

This is my plan.