我有一个工作表,它在单元格中存储软件版本号,它使用多个小数点。例如5.2.16
我需要能够进行版本号比较。单元格中的版本号是高于还是低于版本号I与其进行比较。
Double只能存储一个带小数点的数字,因此该数字已经用完了。
我尝试过的一种方法是使用Replace删除小数并将数字存储在Long变量中。
lngMyNumber = Replace("5.2.16", ".", "")
然后我可以轻松地比较数字,但当然如果将版本号5.1(51)与4.5.10(4510)进行比较,5.1将不会作为更高的版本号出现。
有没有人对优雅的解决方案有任何建议?
答案 0 :(得分:1)
我认为这是一种更强大的方法,因为它不假设版本组件的长度相同:
Function VersionCheck(currVer, latestVer) As Boolean
Dim currArr() As String, latestArr() As String
currArr = Split(currVer, ".")
latestArr = Split(latestVer, ".")
'If versions are the same return true
If currVer = latestVer Then
VersionCheck = True
Exit Function
End If
'Iterate through the version components
Dim i As Integer
For i = LBound(currArr) To UBound(currArr)
'If the end of the latest cersion is reached, the current version must be up to greater
'meaning it is up to date
If i > UBound(latestArr) Then
VersionCheck = True
Exit Function
End If
'Cast the component to an integer
Dim curr As Integer, latest As Integer
curr = Int(currArr(i))
latest = Int(latestArr(i))
'Check which version component is greater in which case return a result
If curr > latest Then
VersionCheck = True
Exit Function
ElseIf curr < latest Then
VersionCheck = False
Exit Function
End If
'If the version components are equal, iterate to the next component
Next
'If there are remaining components in the latest version, return false
If i < UBound(latestArr) Then
VersionCheck = False
Exit Function
End If
结束功能
答案 1 :(得分:0)
这应该有效。将替换的版本号传递给函数以及所需的长度,该长度应为版本的最大字符串长度。
Function rightSize(ver, verlen As Integer) As Long
Dim i As Integer
For i = Len(ver) To verlen - 1
ver = ver & "0"
Next
rightSize = Int(ver)
End Function
答案 2 :(得分:0)
一种更简单的解决方法,适用于不同长度的版本号。
arangodb:
loadBalancer:
servers:
- url: "http://arango-coordinator:7001"