数组 简单问题

accomp 2009-08-13 11:28:05
定义一数组
Dim item(10) As String
item(0) = "AA"
item(1) = "BB"
item(2) = "CC"
item(3) = "DD"
item(4) = "EE"
......

有一个字符串 str ,怎么判断他是否是数组里面所包含的? 有类似于c#的 contains方法么?
...全文
80 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
倒大霉的上帝 2009-08-13
  • 打赏
  • 举报
回复

Private Sub Command1_Click()
Dim item(10) As String
Dim str As String

str = "BC"

item(0) = "AB"
item(1) = "CD"
item(2) = "EF"
item(3) = "GH"
item(4) = "IJ"

'HAVE提示的时候,其实是没有的。
If InStr(1, Join(item, ","), str) > 0 Then MsgBox "have"

End Sub
脆皮大雪糕 2009-08-13
  • 打赏
  • 举报
回复

Private Sub Command1_Click()
Dim a As New Collection
a.Add "aa", "aa"
a.Add "bb", "bb"
a.Add "dd", "dd"
a.Add "ee", "ee"
a.Add "ff", "ff"

Debug.Print FindInCol(a, "dd")
Debug.Print FindInCol(a, "zz")
End Sub


Private Function FindInCol(col As Collection, strFind As String) As Boolean
On Error GoTo ErrHandle
Dim a As Variant
FindInCol = True
a = col(strFind)
Exit Function
ErrHandle:
FindInCol = False
End Function
jhone99 2009-08-13
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim item(10) As String
Dim str As String

str = "DD"

item(0) = "AA"
item(1) = "BB"
item(2) = "CC"
item(3) = "DD"
item(4) = "EE"

If InStr(1, Join(item, ","), str) > 0 Then MsgBox "have"

End Sub
脆皮大雪糕 2009-08-13
  • 打赏
  • 举报
回复
写错了是 集合
脆皮大雪糕 2009-08-13
  • 打赏
  • 举报
回复
试着用几何解决这个问题
贝隆 2009-08-13
  • 打赏
  • 举报
回复
帮顶
倒大霉的上帝 2009-08-13
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 yachong 的回复:]
5楼bestbadgod没测试吧?
[/Quote]
是我错了
yachong 2009-08-13
  • 打赏
  • 举报
回复
5楼bestbadgod没测试吧?
SYSSZ 2009-08-13
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim item(10) As String
Dim str As String
Dim i
str = "DD"
item(0) = "AA"
item(1) = "BB"
item(2) = "CC"
item(3) = "DD"
item(4) = "EE"
For i = 0 To 10
If item(i) = str Then MsgBox "有" & str
Next
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧