Arrays 两个相同的数字不相等

Arrays 两个相同的数字不相等,arrays,vba,comparison,equals,Arrays,Vba,Comparison,Equals,我不明白为什么输出值不相等,因为它们看起来是一样的。可能是太明显了,我看不见。 部分代码不是我的,我也不完全理解 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) elem

我不明白为什么输出值不相等,因为它们看起来是一样的。可能是太明显了,我看不见。 部分代码不是我的,我也不完全理解

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

错误在哪里?哪两个数字?请提供更多信息。当我运行脚本时,在第三个子部分中,即使元素(q)与getpos(r)相同,if条件也不会触发MsgBox。