Function String Numerics Class

VersionNumberCompare

Compares two version numbers to determine whether one is less than, equal to, or greater than the other. The first most significant sections of the version number are compared, and if they match successive less-significant sections are compared to break the tie.

Signature (Visual Basic / VBA)

Public Function VersionNumberCompare( _
      ByVal vV1 As Variant _
    , ByVal vV2 As Variant _
    ) As Integer

Code Examples

    VersionNumberCompare("1.1.5", "1.2.3") = -1
    VersionNumberCompare("1.0.3", "1.0.5") = -1
    VersionNumberCompare("2.0.3", "2.0.3") = 0
    VersionNumberCompare("1.0.34", "1.0.5") = 1 ' #4
    If vV1 < vV2, return -1.
    If vV1 = vV2, return 0.
    If vV1 > vV2, return 1.

Parameters

Parameter Description
vV1 First of the two version numbers to be compared. The version number strings can contain any number of numeric sections which are each separated by a period (.). Each section is interpreted numerically as illustrated by example #4. Function returns Null if vV1 is Null or cannot be fixed up to a String.
vV2 Second of the two version numbers to be compared. Function returns Null if vV2 is Null or cannot be fixed up to a String.