Re: Compare Version Number Strings
I have the same problem, so I wrote a quick function to solve the problem. It works quite well and even if you use letters in your version it still works. Obly if you compare capital with small letters weird things are happening (but for my purpose there are just small letters in use).
Code
Function VersionCompare(Version1 As String, Version2 As String) As Integer'returns 1 if Version 1 is newer
'returns -1 if version 1 is older
'returns 0 if both versions are the same
Dim i As Integer
Dim Version1Array() As String
Dim Version2Array() As String
Version1Arry = Split(Version1, ".")
Version2Arry = Split(Version2, ".")
For i = 0 To Application.Min(UBound(Version1Arry), UBound(Version2Arry))
If Version1Arry(i) > Version2Arry(i) Then
VersionCompare = 1
Exit For
ElseIf Version1Arry(i) < Version2Arry(i) Then
VersionCompare = -1
Exit For
Else
If UBound(Version1Arry) = UBound(Version2Arry) Then
VersionCompare = 0
ElseIf UBound(Version1Arry) > UBound(Version2Arry) Then
VersionCompare = 1
Else
VersionCompare = -1
End If
End If
Next i
End Function
Display More
I am happy if you have some feedback or if you find a better solution/improvement. Thanks.