其他 结束如果 - A)bort,R)etry,I)用大锤子影响。 What I''d like to do is create an array of values and test for existence ofthose values.Here''s the non-working code I''m having trouble with: Dim wcSearch(4 To 7) As Integer If Me.Value = wcSearch ThenDo SomethingElseDo Something elseEnd If Compile Error: Type mismatch <<=== error when try to compile Anyone know how to do this with a VBA array? Thanks in advance! 解决方案 Dim wcSearch(4 To 7) As IntegerDim i As Integer For i = LBound(wcSearch) To UBound(wcSearch)If Me.Value = wcSearch(i) ThenDo SomethingExit ForElseDo Something elseEnd IfNext iWayne GillespieGosford NSW Australia Dim wcSearch(4 To 7) As Integer Dim i As Integer For i = LBound(wcSearch) To UBound(wcSearch) If Me.Value = wcSearch(i) Then Do Something Exit For Else Do Something else End If Next i Wayne Gillespie Gosford NSW AustraliaDim wcSearch(4 To 7) As IntegerDim i As IntegerFor i = LBound(wcSearch) To UBound(wcSearch) If Me.Value = wcSearch(i) Then Do Something Exit For Else Do Something else End IfNext i Not sure you''d want to "Do something else" at that point, perhaps... For i = LBound(wcSearch) To UBound(wcSearch)If Me.Value = wcSearch(i) ThenDo SomethingExit ForEnd IfNext iIf i > UBound(wcSearch) Then'' exited For loop naturally'' so didn''t find oneDo Something ElseEnd If --A)bort, R)etry, I)nfluence with large hammer. 这篇关于VBA阵列基础 - 如何测试价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-26 18:10