VBA阵列基础 - 如何测试价值? [英] VBA array basics - how to test for value?

查看:62
本文介绍了VBA阵列基础 - 如何测试价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是创建一系列值并测试这些值是否存在



这里是非工作代码我遇到了麻烦:


昏暗的wcSearch(4到7)作为整数


如果Me.Value = wcSearch那么

做点什么

否则

别的东西

结束如果


编译错误:尝试编译时键入不匹配<< ===错误


任何人都知道如何使用VBA数组执行此操作?


提前致谢!

解决方案

2003年9月30日星期二23:18:00 GMT,deko < DJ **** @ hotmail.com>写道:

我想做的是创建一个值数组并测试这些值是否存在。
这里是非 - 工作代码我遇到了麻烦:

昏暗的wcSearch(4到7)作为整数

如果Me.Value = wcSearch那么
做某事<其他
做其他事情
结束如果

编译错误:尝试编译时键入不匹配<< ===错误

有人知道怎么用VBA数组做这个吗?

提前致谢!




Dim wcSearch(4 To 7)As Integer

Dim i As Integer


for i = LBound(wcSearch)to UBound(wcSearch)

如果Me.Value = wcSearch(i )然后

做点什么

退出

否则

做其他事情

结束如果

下一页我

Wayne Gillespie

Gosford NSW澳大利亚


谢谢答复。该代码似乎工作正常,但我只是发现了我需要将数组的内容更改为:

Dim wcSearch(1) ,2,3,8,9)作为整数


但行:


对于i = LBound(wcSearch)到UBound(wcSearch )


现在似乎无法正常工作。


如何补救?


再次感谢!!


" Wayne Gillespie" <是***** @ NObestfitsoftwareSPAM.com.au>在消息中写道

新闻:b8 ******************************** @ 4ax.com ...

2003年9月30日星期二23:18:00 GMT,deko < DJ **** @ hotmail.com>写道:

我想要做的是创建一个值数组并测试存在
的值。
这里是非工作代码我遇到了麻烦:

昏暗的wcSearch(4到7)作为整数

如果Me.Value = wcSearch那么
做某事做其他事情
结束如果

编译错误:尝试编译时键入不匹配<< ===错误

任何人知道如何用VBA阵列做到这一点吗?

提前致谢!



Dim wcSearch(4 To 7)As Integer
Dim i As整数

对于i = LBound(wcSearch)到UBound(wcSearch)
如果Me.Value = wcSearch(i)那么
做某事
退出其他
做其他事情
结束如果
接下来我

Wayne Gillespie
Gosford NSW Australia



2003年9月30日星期二23:28:55 GMT在comp.databases.ms-acc ess,Wayne

Gillespie< be ***** @ NObestfitsoftwareSPAM.com.au>写道:

在星期二,2003年9月30日23:18:00 GMT,deko < DJ **** @ hotmail.com>写道:

我想做的是创建一个值数组并测试这些值是否存在。
这里是非 - 工作代码我遇到了麻烦:

昏暗的wcSearch(4到7)作为整数

如果Me.Value = wcSearch那么
做某事<其他
做其他事情
结束如果

编译错误:尝试编译时键入不匹配<< ===错误

有人知道怎么用VBA阵列吗?

提前致谢!



Dim wcSearch(4 To 7)As Integer
Dim i作为整数

对于i = LBound(wcSearch)到UBound(wcSearch)
如果Me.Value = wcSearch(i)然后
做某事
退出
其他
做其他事情
结束如果
接下来我




不确定你想要做点什么否则"在那一点,也许......


对于i = LBound(wcSearch)到UBound(wcSearch)

如果Me.Value = wcSearch(i)那么

做点什么

退出

结束如果

下一页我

如果我> UBound(wcSearch)然后

''退出For循环自然

''所以没找到一个

做其他事情
结束如果


-

A)bort,R)etry,I)用大锤子影响。


What I''d like to do is create an array of values and test for existence of
those values.
Here''s the non-working code I''m having trouble with:

Dim wcSearch(4 To 7) As Integer

If Me.Value = wcSearch Then
Do Something
Else
Do Something else
End If

Compile Error: Type mismatch <<=== error when try to compile

Anyone know how to do this with a VBA array?

Thanks in advance!

解决方案

On Tue, 30 Sep 2003 23:18:00 GMT, "deko" <dj****@hotmail.com> wrote:

What I''d like to do is create an array of values and test for existence of
those values.
Here''s the non-working code I''m having trouble with:

Dim wcSearch(4 To 7) As Integer

If Me.Value = wcSearch Then
Do Something
Else
Do Something else
End 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 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 Australia


Thanks for the reply. That code seems to work okay, but I''ve just
discovered I need change the contents of the array to something like:

Dim wcSearch(1, 2, 3, 8, 9) As Integer

But the line:

For i = LBound(wcSearch) To UBound(wcSearch)

does not appear to work now.

How to remedy?

Thanks again!!

"Wayne Gillespie" <be*****@NObestfitsoftwareSPAM.com.au> wrote in message
news:b8********************************@4ax.com...

On Tue, 30 Sep 2003 23:18:00 GMT, "deko" <dj****@hotmail.com> wrote:

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 Then
Do Something
Else
Do Something else
End 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 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 Australia



On Tue, 30 Sep 2003 23:28:55 GMT in comp.databases.ms-access, Wayne
Gillespie <be*****@NObestfitsoftwareSPAM.com.au> wrote:

On Tue, 30 Sep 2003 23:18:00 GMT, "deko" <dj****@hotmail.com> wrote:

What I''d like to do is create an array of values and test for existence of
those values.
Here''s the non-working code I''m having trouble with:

Dim wcSearch(4 To 7) As Integer

If Me.Value = wcSearch Then
Do Something
Else
Do Something else
End 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 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



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) Then
Do Something
Exit For
End If
Next i
If i > UBound(wcSearch) Then
'' exited For loop naturally
'' so didn''t find one
Do Something Else
End If

--
A)bort, R)etry, I)nfluence with large hammer.


这篇关于VBA阵列基础 - 如何测试价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆