怎么判断 list1里面的所有地址是否重复? 谢谢

解决方案 »

  1.   

    可以使用一个字符串数,每添加一个list项目,先判断instr(1,str,list1,list)是否为0,
    为0 str=str & "/" list1.list
    否则,str操作,就可以了,对于应经添加好的,用for操作一遍上面的方法
      

  2.   

    你把一个复本吧,,,,把一个数组    dim a() as integer 把你每一次的数据 存a()里,在这个数组里查,有没有重复,,,,这样速度快点
      

  3.   

    1、listbox有排序功能(List1.Sorted=True)
    2、List1.List是一个列表项的集合,故只需一次循环比较即可:
    Dim hasRepeat As Boolean
    List1.Sorted=True
    For i=0 To List1.ListCount-2
         If List1.List(i)=List1.List(i+1) Then
            hasRepeat=True
            Exit For
         End If
    Next
      

  4.   

    Sorted是只读属性,不能在运行期间设置。应该删除这句,在窗体设计阶段把list1的Sorted设置为TRUE即可。
    其实,我还是力推Dictionary对象,就因为Dictionary对象的Exists方法很好很强大,我举个例子:
    Private Sub Command1_Click()    Dim Dic As Object
        Set Dic = CreateObject("Scripting.Dictionary")    Dim i As Long
        
        For i = 0 To List1.ListCount - 1
            If Dic.Exists(List1.List(i)) Then
                MsgBox "list1里面的所有地址是存在重复的"
                Exit Sub
            Else
                Dic.Add List1.List(i), i
            End If
        Next
        
    End SubPrivate Sub Form_Load()    List1.AddItem "a"
        List1.AddItem "b"
        List1.AddItem "a"
        
    End Sub自己上VB的帮助文档看吧,下面列点内容
    Exists 方法
             
    描述如果在 Dictionary 对象中指定的关键字存在,返回 True,若不存在,返回 False。语法object.Exists(key)Exists 方法语法有如下几部分:部分 描述 
    Object 必需的。始终是一个 Dictionary 对象的名字。 
    Key 必需的。在 Dictionary 对象中搜索的 Key 值。 
      

  5.   

    别把问题想得太复杂了。Dim x, y, k As Long
    For x = 0 To List1.ListCount - 2
       For y = x + 1 To List1.ListCount - 1
          If List1.List(x) = List1.List(y) Then MsgBox "第 " & x & "行地址和第 " & y & "行地址内容重复!": k = k + 1 '注意list1列表的行是以0开始的!
       Next y
    Next x
    If k = 0 Then MsgBox "list1没有重复地址!"
    End Sub