列表项是数字时列表框溢出问题

时间:2011-07-08 08:16:08

标签: vb6

listbox总是溢出,有超过数千个项目,我需要一种摆脱这个的方法..我需要使用一个可以作为列表框的替代对象!

Private Sub difference_Click()

    'Find differences and show'

    j = 0

    For i = 0 To secretlist1.ListCount - 1

        'If i use 2nd "for" with J it would cause to get same items again and again!
        'for that reason im not gonna do that instead im using a definition for j as long
        'but it keeps overflow problem so icant use it either.

        If Val(secretlist2.List(i)) <> Val(secretlist1.List(j)) Then

            lostonelist.Visible = True 'show the lostonelist
            lostonelist.AddItem secretlist1.List(j) 'add the items which are not in list2
            i = i - 1 'if they r not equal to each other move list2 index to previous one

        End If

        j = j + 1 

        'we moved list2 index to previous cause list1 index always will be increasing
        'and when they r not equal to eachother we must make sure that next item in list1
        'will be compared with the same item in list2

    Next

End Sub

或者使用Do While更简单的方法:

Private Sub difference_Click()

    'Find differences and show'
    j = 0
    i = 0
    'For i = 0 To secretlist1.ListCount - 1
    Do While Not secretlist1.ListCount - 1

        If Val(secretlist2.List(i)) <> Val(secretlist1.List(j)) Then

            lostonelist.Visible = True
            lostonelist.AddItem secretlist1.List(j)
            i = i - 1

        End If

        j = j + 1
        i = i + 1

    Loop

End Sub

我正在尝试的是搜索不在secretlist2中的项目,当它们仍然在secretlist1中时。在这些列表框中,我的所有项目都是数字,其中任何一个都没有字符串。 但“secretlist1(j)”总是溢出我需要一种摆脱这个的方法..我有列表项目的thousans。我需要另一个我可以用作列表框的对象,我仍然在寻找解决方案,我认为这是一个很好的例子,当我找到答案之前你才能找到..生病发布在这里。 Ty已经。

重要说明:这是一个Visualbasic 6项目而不是.NET项目!

我正在制作这个教导我的小弟弟的例子!但是在做“facepalm”xD

时,我会溢出自己

1 个答案:

答案 0 :(得分:1)

考虑添加通过“数据”“分页”的功能。很多记录 超出了对一个人的用处。

使用分页和一些经过深思熟虑的搜索例程而不是 向用户抛出所有数据并祈求结果。

无论你在做什么,很多行都需要时间。

建议 改变你的设计

其他,使用apis 例如,在列表框中搜索

L = SendMessage(cList.hwnd,LB_FINDSTRINGEXACT,-1,ByVal sText)

使用windows目录填充

SendMessage List1.hwnd,LB_DIR,DDL_READWRITE,“* .asp”

===其他选项索引你的项目如何

private m_indexData as collection

private sub loadInfo()
dim rs as adodb.recordset

rs = IProductRepository.GetAll()

PopulateIndex indexData, rs
End sub

private sub PopulateIndex(byref indexdata as collection, rs as adodb.recorset)
.....
end sub

class itemselected 'that is conceptual class for indexdata
    key as string
    description as strin
    location as location
end class

enum location
    [user list A]
    [user list B]
    [secret list C]
end enum

'//now user actions

public sub FindDiferences()
  dim subcollection as collection 
    subcollection = filtercollection(indexdata, [sectet list c])
end sub

public function filterCollection (data as collection, location as location) as Collection
    ....
end function