0
如何使VB6列表計數對超過32767項目的列表工作?當列表很長時,VB6列表循環不起作用
for k = 0 to List2.ListCount - 1
''do stuff
next
上面的代碼的偉大工程,直到我在我的名單有太多的項目,然後列表計數得到所有擰緊和變負。
我該如何解決這個問題?我可以讓ListCount成爲一個長數據類型嗎?
如何使VB6列表計數對超過32767項目的列表工作?當列表很長時,VB6列表循環不起作用
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仍然可能是一個好理念。
剛剛發現List2.ListCount - 1正在返回(-21867)WTF? –
當它是因爲List2.ListCount - 1是一個整數數據類型。我怎樣才能使它成爲一個長數據類型? arghh –
在列表中有超過32000個項目有什麼意義? – dbmitch