How i can Compare two file version? RRS feed

  • Question

  • How i can Compare two file version?




    Which is Newer?

    with VB.Net or C#

    Unfortunately, I can not speak English well I am a beginner programmer. I love the improvements

    Thursday, June 20, 2013 9:32 AM

All replies

  • You've posted in the MS Project forum, although your query doesn't appear to relate directly to MSP.

    However, if you pass the two numbers to the following VBA funtion, it will tell you which is newer. Note this is VBA, so you may need to do some rework for VB.Net.

    Function WhichIsNewer(version0 As String, version1 As String) As String
        Dim split_Version0() As String
        Dim split_Version1() As String
        Dim i As Integer
        'if both numbers are the same, then throw an error
        If version0 = version1 Then
            MsgBox "The compared version numbers are the same." & vbCrLf & vbcrlf & "Unable to determine which is newer."
            WhichIsNewer = "#Error - Identical Version Numbers compared."
            Exit Function
        End If
        split_Version0() = Split(version0, ".")
        split_Version1() = Split(version1, ".")
        'if both numbers split into a different number of components, then throw an error
        If UBound(split_Version0) <> UBound(split_Version1) Then
            MsgBox "These version numbers contain an inconsistent number of elements." & vbCrLf & vbcrlf & "Unable to determine which is newer."
            WhichIsNewer = "#Error - Inconsistent number of elements"
            Exit Function
        End If
        For i = 0 To UBound(split_Version0)
            If split_Version0(i) <> split_Version1(i) Then
                'if version 0 has a higher number than version 1, then it is newer
                If split_Version0(i) > split_Version1(i) Then
                    WhichIsNewer = "Version0"
                    Exit Function
                Else 'otherwise, version 1 must be higher
                    WhichIsNewer = "Version1"
                    Exit Function
                End If
            End If
        Next i
        'The code should theoretically never get to this point,
        'but included for completeness, just in case.
        MsgBox "Unknown error." & vbCrLf & vbcrlf & "Unable to determine which is newer."
        WhichIsNewer = "#Error - Unknown error"
        Exit Function
    End Function
    (Note, it will only work for numeric version numbers, if there are any letters in the version numbers this will not work, e.g. "3.1.4a")

    • Edited by Andrew Simpson Thursday, June 20, 2013 12:36 PM correcting vbcrlf type
    Thursday, June 20, 2013 12:34 PM