【问题标题】:Compare 2 numbers with up to 4 decimal points比较最多 4 个小数点的 2 个数字
【发布时间】:2014-08-07 00:47:02
【问题描述】:

我需要比较最多有 4 位小数的软件版本 (14.7.3.13)。我有一个静态列表,我正在将电子表格中的值与之进行比较。如果电子表格中的值 >= 我的代码中的静态数字,我会突出显示该单元格。 我很难做到这一点。我假设我的问题是数据类型。我已将我的静态值声明为变体。我可以更改电子表格中的数据类型,但我不知道要在电子表格的代码中使用哪些数据类型。

【问题讨论】:

  • 你能不能把它当作一个标准的文本字段,然后在'.'上拆分软件版本。字符,然后比较版本的每个单独“段”?

标签: excel comparison excel-2010 decimal-point vba


【解决方案1】:

您能否拆分“.”上的软件版本?字符,然后比较版本的每个单独的“段”?像这样:

Dim value1() As String = version1.split(".")
Dim value2() As String = version2.split(".")
Dim greatestVersion As String

greatestVersion = value1 ' Start with greatest version as value1

If version1 = version2 Then ' Check to see if they are both the same
    greatestVersion = "BOTH THE SAME!"
Else If ' If not the same then determine the bigger value
For i=0 To value1.count
    If value2[i] > value1[i] Then
        greatestVersion = version2
    End If
Next




End If

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-02
    • 2012-08-16
    相关资源
    最近更新 更多