VBA 两个相同的数字不相等



我不明白为什么输出值不相等,因为它们看起来相同。可能是很明显的东西,以至于我没有看到它。 部分代码不是我的,我不完全理解它。

Sub main()
Dim elements As Variant, vresult As Variant
Dim i As Long
Dim combolist As Variant
ReDim combolist(0)
stringg = "0aaaaaaa"
ReDim elements(Len(stringg))
For k = 1 To Len(stringg)
elements(k) = k
Next
MsgBox Join(elements, ",")
For i = 1 To UBound(elements)
ReDim vresult(1 To i)
Call Combinations(elements, i, vresult, 1, 1, combolist)
Next i
Call checkk(combolist, stringg, elements)
End Sub
Sub Combinations(elements, p, vresult, startpos, index, combolist)
Dim i As Long

For i = startpos To UBound(elements)
vresult(index) = elements(i)
If index = p Then
combolist(UBound(combolist)) = Join(vresult, ",")
ReDim Preserve combolist(UBound(combolist) + 1)
Else
Call Combinations(elements, p, vresult, i + 1, index + 1, combolist)
End If
Next i
End Sub
Sub checkk(combolist, stringg, elements)
Dim q As Long, r As Long
For k = LBound(combolist) To UBound(combolist)
getpos = Split(combolist(k), ",")
For q = 1 To UBound(elements)
For r = LBound(getpos) To UBound(getpos)
MsgBox elements(q) & " - " & getpos(r)
If elements(q) = getpos(r) Then
MsgBox "found"
End If
Next
Next
Next
End Sub

你应该定义所有的变量,包括你的数组。一个可能是整数,另一个是小数,或者可能存在大写和小写的问题。您的代码中实际上没有太多信息来提供很多信息。

我会逐步完成您的代码并将其设置为在您知道它们应该相等时停止......

这是一个尝试调试上一个例程的工具,希望您可以自己解决它:

Sub checkk(combolist, stringg, elements)
Const theNUmberYouKnow as double = 4
Dim q As Long, r As Long
For k = LBound(combolist) To UBound(combolist)
getpos = Split(combolist(k), ",")
For q = 1 To UBound(elements)

For r = LBound(getpos) To UBound(getpos)
MsgBox elements(q) & " - " & getpos(r)
If elements(q) = getpos(r) OR elements(q) = theNUmberYouKnow Then
msgbox "R = " & getpos(r)
Stop

MsgBox "found"
End If
Next
Next
Next
End Sub

最新更新