udfStrCmpVersion
#DefineFunction udfStrCmpVersion (strString1, strString2, strDelim, blnMatchCase)
intCountMax = Max (ItemCount (strString1, strDelim), ItemCount (strString2, strDelim))
intResult = 0
For intCount = 1 To intCountMax
   strItem1 = ItemExtract (intCount, strString1, strDelim)
   strItem2 = ItemExtract (intCount, strString2, strDelim)
   intItemLen = Max (StrLen (strItem1), StrLen (strItem2))
   strItem1 = StrFixLeft (strItem1, "0", intItemLen)
   strItem2 = StrFixLeft (strItem2, "0", intItemLen)
   If blnMatchCase
      intResult = StrCmp (strItem1, strItem2)
   Else
      intResult = StriCmp (strItem1, strItem2)
   EndIf
   If intResult Then Break
Next
Return intResult
;..........................................................................................................................................
; This function "udfStrCmpVersion" compares two "version strings".
;
; A "version string" is a string composed by sequences of numbers and/or characters,
; which are delimited, for example, by a single period character, e.g. "1.11.1111" or "2002.abc".
; The given strings are evaluated from left to right, item by item.
;
; This udf returns an integer value -1, 0, or 1,
; depending on whether strString1 is less than, equal to, or greater than strString2.
;..........................................................................................................................................
; Detlev Dalitz.20020125.20020817.20111026.
;..........................................................................................................................................
#EndFunction


; Test.

intTestMin = 1
intTestMax = 10
strListRelation = "less than,equal to,greater than"
strListBoolean = "@FALSE,@TRUE"
strDelim = "."

For intTest = intTestMin To intTestMax
   GoSub Test%intTest%
   intCmpResult = udfStrCmpVersion (strVersion1, strVersion2, strDelim, blnMatchCase)
   strRelation = ItemExtract (2 + intCmpResult, strListRelation, ",")
   strMsgText = 'Test ' : intTest : ' of ' : intTestMax : @LF : @LF
   strMsgText = strMsgText : 'Version1 = "' : strVersion1 : '"' : @LF
   strMsgText = strMsgText : 'Version2 = "' : strVersion2 : '"' : @LF : @LF
   strMsgText = strMsgText : 'MatchCase = ' : ItemExtract (1 + blnMatchCase, strListBoolean, ",") : @LF : @LF
   strMsgText = strMsgText : 'Version1 is ' : strRelation : ' Version2' : @LF
   Pause ("Test: udfStrCmpVersion (strVersion1, strVersion2, blnMatchCase)", strMsgText)
Next

:CANCEL
Exit


; Test cases.
:Test1
; Version1 is equal to version2.
blnMatchCase = @TRUE
strVersion1 = ""
strVersion2 = ""
Return
:Test2
; Version1 is less than version2.
blnMatchCase = @TRUE
strVersion1 = "9.900.09"
strVersion2 = "10.40.0101"
Return
:Test3
; Version1 is greater than version2.
blnMatchCase = @TRUE
strVersion1 = "10.900"
strVersion2 = "10.40.0101"
Return
:Test4
; Version1 is equal to version2.
blnMatchCase = @TRUE
strVersion1 = "10.900"
strVersion2 = "10.000900"
Return
:Test5
; Version1 is greater than version2 if matchcase is 1 (@TRUE).
blnMatchCase = @TRUE
strVersion1 = "2002A"
strVersion2 = "2002a"
Return
:Test6
; Version1 is equal to version2 if matchcase is 0 (@FALSE).
blnMatchCase = @FALSE
strVersion1 = "2002A"
strVersion2 = "2002a"
Return
:Test7
; Version1 is greater than version2.
blnMatchCase = @TRUE
strVersion1 = "5.6.0.6626"
strVersion2 = "5.6.0.1111"
Return
:Test8
; Version1 is greater than version2.
blnMatchCase = @TRUE
strVersion1 = "8.0.7600.16385"
strVersion2 = "8.0.345.22347"
Return
:Test9
; Version1 is less than version2.
blnMatchCase = @TRUE
strVersion1 = "8.0.345.001638"
strVersion2 = "8.0.345.22347"
Return
:Test10
; Version1 is less than version2.
blnMatchCase = @TRUE
strVersion1 = "8.0"
strVersion2 = "8.0.345.22347"
Return