如何使VB6列表计数与超过32767项的列表工作?
for k = 0 to List2.ListCount - 1
''do stuff
next
上面的代码工作得很好,直到我的列表中有太多的项目,然后列表计数得到所有的螺旋和负。
我该如何解决这个问题?我可以让ListCount是一个长数据类型吗?
虽然VB6属性只有签名Integer
,但底层控件使用32位整数,因此您可以使用Windows API来操作您的列表:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const LB_GETCOUNT = &H18B
Private Const LB_GETTEXT = &H189
Private Sub Command1_Click()
Dim ix As Long
For ix = 0 To 40000
List1.AddItem "X" + Format(ix)
Next
End Sub
Private Sub Command2_Click()
Dim rc As Long
Dim wp As Long
Dim lp As Long
Dim s As String * 1000
' Get count of items into rc
rc = SendMessage(List1.hwnd, LB_GETCOUNT, 0, 0)
' Get the 39001th item
rc = SendMessageString(List1.hwnd, LB_GETTEXT, 39000, s)
MsgBox s
End Sub
切换到ListView可能仍然是一个好主意