|
-
May 20th, 2010, 10:43 AM
#1
ListBox.ListCount
While playing with this recursive directory search in the other thread I came upon something I never noticed in about ten years VB6 experience, and wanted to ask if someone knows it too, and can probably mention a remedy:
Put a ListBox on a Form and in Form_Load() fil it with 32000 items.
After that Debug.Print List1.ListCount. Looks good.
Now fill it with 40000 items and you get printed -25536 which, as is obvious, is the representation of 40000 as a signed 16bit integer.
More weird is the fact that the ListBox can easily accept more than 200000 items, but the .ListCount property always is within the signed 16 bit range.
This seems to make the .ListCount property worthless as soon you expect more than 32767 entries in a ListBox.
Anyone knows this phenomenon, or even better has a patch for it?
-
May 20th, 2010, 11:24 AM
#2
Re: ListBox.ListCount
Sure. It's a built-in limit. Can only address 32K items
-
May 20th, 2010, 11:56 AM
#3
Re: ListBox.ListCount
I get an error if I try to add more than 32767 items.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
May 20th, 2010, 12:47 PM
#4
Re: ListBox.ListCount
That's interesting. And funny. How do you add items, Wiz?
I can add 500000 (half a million) items no problem and no error. And the items are really there, visible in the list.
-
May 20th, 2010, 02:08 PM
#5
Re: ListBox.ListCount
 Originally Posted by WoF
That's interesting. And funny. How do you add items, Wiz?
I can add 500000 (half a million) items no problem and no error. And the items are really there, visible in the list.
Using the AddItem method, of course.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
May 20th, 2010, 02:19 PM
#6
Re: ListBox.ListCount
I do:
Code:
Dim i&
For i=1 To 500000: List1.AddItem Format(i, "000000"): Next
without any problem or error.
Only afterwards the .ListCount property behaves as I have described before.
-
May 20th, 2010, 02:27 PM
#7
Re: ListBox.ListCount
That is odd. I have no idea how you could add that many items to the list without an error [bug in list box?] I wonder what would happen if you try to access the selected item when that item is deeper than 32k into the list?
Always use [code][/code] tags when posting code.
-
May 20th, 2010, 02:32 PM
#8
Re: ListBox.ListCount
I just added 100k items to a listbox when I select the last item the text property returns the data selected. The List index property was around -31k
Always use [code][/code] tags when posting code.
-
May 20th, 2010, 03:16 PM
#9
Re: ListBox.ListCount
Yes, i just tried too. The .Text property returns the selected item. ListIndex is, however, as scrambled as ListCount, like signed 16bit quantity.
Accessing elements with an index above 32767 is impossible though.
Print List1.List(50000) produces an overflow error.
I think that's really weird.
The ListBox accepts so many elements and does not allow to count or retrieve them.
-
May 20th, 2010, 05:00 PM
#10
Re: ListBox.ListCount
Simple... 
Tells me David is 8642001
Code:
Option Explicit
Private Sub Combo1_Click()
Dim msg As String
' MsgBox Combo1.Text
msg = Combo1.ItemData(Combo1.ListIndex) & " "
msg = msg & Combo1.List(Combo1.ListIndex)
MsgBox msg
End Sub
Private Sub Form_Load()
' Could also use ' List1.ItemData(0) = 5
List1.AddItem "David G"
List1.ItemData(List1.NewIndex) = 8642001 ' New Index
List1.AddItem "Greg G"
List1.ItemData(List1.NewIndex) = 8642000 ' New Index
Combo1.AddItem "David G"
Combo1.ItemData(Combo1.NewIndex) = 42001 ' New Index
Combo1.AddItem "Greg G"
Combo1.ItemData(Combo1.NewIndex) = 42000 ' New Index
End Sub
Private Sub List1_Click()
' Append Name to ItemData
Dim msg As String
' msgbox list1.text
msg = List1.ItemData(List1.ListIndex) & " "
msg = msg & List1.List(List1.ListIndex)
MsgBox msg
End Sub
-
May 20th, 2010, 06:14 PM
#11
Re: ListBox.ListCount
Sorry, I don't quite get what it is you want to say with that code.
-
May 20th, 2010, 07:05 PM
#12
Re: ListBox.ListCount
Nor do I, Only 2 items in the list and the number is hard coded into item data, naturally it will return what you coded into it.
Always use [code][/code] tags when posting code.
-
May 20th, 2010, 07:13 PM
#13
Re: ListBox.ListCount
Well, if you add a million items, in order, then they'd return the index in order.
EDIT: Then there's the Net Framework...
Last edited by dglienna; May 20th, 2010 at 07:29 PM.
-
May 20th, 2010, 08:03 PM
#14
Re: ListBox.ListCount
return the index?
the index is no longer valid once it exceeds the bounds allowed. Sure if you set the item data to the number which should be the index and someone clicks on that item you could get that number for all the good it would do you.
You can't reference the listindex or list1.list(x) or listcount once it exceeds the bounds so I fail to see what the fact that you can add somthing larger into itemdata actually would be useful for in this case.
Always use [code][/code] tags when posting code.
-
May 20th, 2010, 09:07 PM
#15
Re: ListBox.ListCount
Just use an array() and adjust the lower and upper bounds to that of the listbox
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|