【发布时间】:2018-09-24 16:26:46
【问题描述】:
我正在使用输入框在数组中查找元素。这是我目前拥有的:
arrayNumber = InputBox("Please enter your desired number.")
For i = 0 To 9
If arrayNumber = data(i) Then
outputMessage1 = ("Your number is found in the first array. " & i & " is the index of the desired number.")
Else
End If
Next
For i = 0 To 9
If arrayNumber = data2(i) Then
outputMessage2 = ("Your number is found in the second array. " & i & " is the index of the desired number.")
Else
End If
Next
For i = 0 To 9
If arrayNumber = data3(i) Then
outputMessage3 = ("Your number is found in the third array. " & i & " is the index of the desired number.")
Else
End If
Next
Selection.TypeText (outputMessage1 & " " & outputMessage2 & " " & outputMessage3)
For i = 0 To 9
If arrayNumber <> i Then
notFound = ("Sorry the element is not found.")
Else
End If
Next
Selection.TypeText (notFound)
...
我目前有两个问题:即使 arrayNumber 确实等于 i,也会弹出 notFound 消息。我该如何解决这个问题?
另外,我知道我目前在每个数组中都有元素的索引。有没有一种方法可以找到元素的最早外观,查看所有三个数组的组合(即,如果 4 是第一个数组中的第三个索引但第二个数组的第二个索引,我想说最早出现在第二个数组)。
【问题讨论】:
-
调试您的代码,即设置断点并逐行执行。一旦实际状态与您的预期不同,您就发现了 n 个问题,您可以专门对此进行调查。至少,您可以向我们描述细节。您不能仅仅通过阅读代码来解决代码问题。您运行它并观察它的实际效果。