TryCompareVersions
Compares two versions.
Compatibility
Available as of IDEA version 10.3
Syntax
TryCompareVersions(version1 As String, version2 As String, result As Long)
Parameters
version1
Returns true if the versions could be compared (no version is null or empty), and false if any of the versions are null or empty.
version2
Returns true if the versions could be compared (no version is null or empty), and false if any of the versions are null or empty.
result
The parameter will contain the result of the comparison in case the function returns true.
| Value | Explanation |
|---|---|
| -1 | If the first version is lower than the second version. |
| 0 | If the versions are equal. |
| 1 | If the first version is greater than the second version. |
In case the two versions have different numbers of elements, the shorter version is concatenated with "0" until it gets the same number of elements as the longer version. Example: that means that "1" = "1.0" = "1.0.0" = "1.0.0.0" or "10.3" = "10.3.0.0".
Type
Boolean
Return Value
Returns Boolean (true if the versions could be compared), false if the versions could not be compared (one or both are empty or not a valid version string).
Example
Option Explicit
Dim oMC As Object
Dim oSC As Object
Sub Main
On Error GoTo ErrorHandler
Dim SAVersion As String
Dim IDEAVersion As String
Dim text As String
Dim result As Long
Set oMC = SmartContext.MacroCommands
Set oSC = oMC.SimpleCommands
SAVersion = GetSAVersion()
If SAVersion <> "" Then
IDEAVersion = oSC.IDEAVersion
text = "SmartAnalyzer version is " & SAVersion & Chr(13) & "IDEA version is " & IDEAVersion & Chr(13) & Chr(13)
If oSC.TryCompareVersions(SAVersion, IDEAVersion, result) Then
Select Case result
Case -1
text = text & "SmartAnalyzer version is smaller than IDEA version."
Case 1
text = text & "SmartAnalyzer version is greater than IDEA version."
Case 0
text = text & "SmartAnalyzer version and IDEA version are the same."
Case Else
text = text & "Invalid result (" & result & ") received when comparing versions!"
End Select
Else
text = text & "The 2 versions cannot be compared."
End If
Else
text = "SmartAnalyzer version could not be found!"
End If
MsgBox text
Exit Sub
ErrorHandler:
MsgBox "Error: " & err.Description
End Sub 'Main
Function GetSAVersion() As String
On Error GoTo ErrorHandler
GetSAVersion = oSC.SmartAnalyzerVersion
Exit Function
ErrorHandler:
GetSAVersion = ""
End Function