Solved

DateDiff VB6 function equivalent Vb.net

Posted on 2012-03-25
4
874 Views
Last Modified: 2012-03-25
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
0
Comment
Question by:luca345
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
You want TotalHours(), not Hours().  *Same thing with Mintues and Seconds.
0
 

Author Closing Comment

by:luca345
Comment Utility
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 ?
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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.
0
 

Author Comment

by:luca345
Comment Utility
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.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now