Just use an array() and adjust the lower and upper bounds to that of the listbox
Why bother to use the list box at all? After all it is not designed to hold that many items and is rather slow to boot. I can't think of anyone who would actually want to scroll through a million items or for that matter even 32k items.
Both the combo box and list box were created back in the 16 bit world of ancient times past, hence the limit on being able to access items over vb's max integer value but in theory, you can add 2^31-1 entries but you would more than likely run out of memory long before you reached that limit.
Okay, time for TMI (Too much information). The additem method is a wrapper for the LB_ADDSTRING message and the wrapper does not impose a limit check but relies on the underlying control, so you are able to add these large amounts of data that eventually, you will not be able to access. Because, ListCount, ListIndex, TopIndex, NewIndex, RemoveItem, and the List Property only accept vb's signed integer as a value.
Also: As a side note, going back to the other thread, using sendmessage with the LB_ADDSTRING message will speed up the loading of the listbox...
I managed to get 500000 items to my listbox, as per attached picture ( ListBox ). It took just about a minute to load!
What is really freaky is that when I do this :
Code:
Private Sub Command2_Click()
Form1.Caption = List1.List(List1.ListIndex)
End Sub
The form's caption turns into an empty string. I clicked on items randomly, sometimes nothing shows up sometimes, but the next item in the list shows the Hex value.
Better explained: If I click on an item, it doesn't show, when I click on an item Just beneath the previous one, it shows the hex value
I doubt that it has something to do with the .NET Framework. I have .NET Framework 1.1, 2.0, 3.0, 3.5 as well as 4.0 on my system. The reason why I say so is when I do this in .NET :
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i&
For i = 1 To 500000 : ListBox1.Items.Add(Format(i, "000000")) : Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Text = ListBox1.SelectedIndex
End Sub
which is the same as this VB 6 code :
Code:
Private Sub Command1_Click()
Dim i&
For i = 1 To 500000: List1.AddItem Format(i, "000000"): Next
End Sub
Private Sub Command2_Click()
Form1.Caption = List1.List(List1.ListIndex)
End Sub
It also takes about a minute to load the list, BUT, it gives me the correct info, as per attached picture ( ListBoxVBNET ).
Well, perhaps it may be due to the .NET Framework, I don't know, why I'm thinking that now is that if people without any .NET Framework gets errors when attempting to add 500000 items to the list, and people with .NET Framework doesn't get errors. Perhaps it is VB 6's limited built in capability?? Perhaps the "new" listbox ( bundled with the Common Controls ) is working properly, but VB 6 cannot handle it?
Then I'm thinking it could be a Service Pack issue, but I doubt...
Both the combo box and list box were created back in the 16 bit world of ancient times past, hence the limit on being able to access items over vb's max integer value but in theory, you can add 2^31-1 entries but you would more than likely run out of memory long before you reached that limit.
Okay, time for TMI (Too much information). The additem method is a wrapper for the LB_ADDSTRING message and the wrapper does not impose a limit check but relies on the underlying control, so you are able to add these large amounts of data that eventually, you will not be able to access. Because, ListCount, ListIndex, TopIndex, NewIndex, RemoveItem, and the List Property only accept vb's signed integer as a value.
Also: As a side note, going back to the other thread, using sendmessage with the LB_ADDSTRING message will speed up the loading of the listbox...
Good Luck
Looks like the whole VB Control is a Wrapper for the control provided with Windows. And this should be 32bit (XP an higher)
Try LB_GETCOUNT using the hWnd from the VB Control.
(LCount = SendMessageLong(ListBoxControl.hWnd, LB_GETCOUNT, 0, 0)
Should get you the correct amount of items in the list.
Yes, using SendMessage seems to be a good idea and possibly the only useful way to skip the integer wrappers of the VB ListBox control. I'm sure there is a LB_GETSTRING and REMOVESTRING message, too. Have to look this up...
It seems in VB.NET other wrapper classes provide correct 32bit properties.
'// SendMessage returns Index of SelectedItem
lpIndex = SendMessageLong(mHlp_hWnd, LB_GETCARETINDEX, 0, 0)
'// Initialise String Var with 1024 Byte
cTemp = Space(1024)
'// SendMessage returns length of returned String
LRes = SendMessageStr(mHlp_hWnd, LB_GETTEXT, lpIndex, cTemp)
'// now reduce the string to actual textsize
cListText = Mid$(cTemp, 1, LRes)
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.