Results 1 to 19 of 19

Thread: Listbox??!!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    249

    Unhappy Listbox??!!

    ye, i was just wondering what is the maximum ammount of items a LitsBox can hold??

  2. #2
    Banned
    Join Date
    Aug 2007
    Posts
    17

    Re: Listbox??!!

    I dont think there is one, it may freeze after so many, but it should load after some time.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Listbox??!!

    There is a 32K limit

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: Listbox??!!

    Unlimited. But listcount and listindex support only 32K, it starts going minus after that. But you can use the API directly.

  5. #5
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Listbox??!!

    A listbox's size is rather huge. I just wrote code to randomly generate 100,000 capped strings of 9 characters apiece. I jump-sorted these in ascending order from AAABXYXQS to ZZZWQMJGD. In 19 seconds the results appeared in the listbox.
    Doctor Ed

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: Listbox??!!

    Also each row is limited to 1024.

    But if you use api its unlimited.

  7. #7
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Listbox??!!

    You'll use API to extend the capacity of listbox. But do you want to get into that much trouble? Dang! Just use listview.

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Listbox??!!

    Quote Originally Posted by Code Doc
    A listbox's size is rather huge...
    It is not - as Hack mentioned it's limited to 32K (but to be exact it's an Integer's boundary of 32767).
    You can load huge amount of list items however you won't be able to access any of it beyond the 32767 index using conventional methods:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim i As Long
    
        For i = 0 To 32768 'you have a million here...
            List1.AddItem i
        Next i
    
    End Sub
    
    Private Sub Command1_Click()
    
        MsgBox List1.List(32768) '<<< you should get an overflow error
    
    End Sub
    So, as Zynder said use Listview control instead.

  9. #9
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Listbox??!!

    Rhino, the OP asked "i was just wondering what is the maximum ammount of items a LitsBox can hold??"
    --------------------
    He said nothing about accessing any of the information in the list box. Right? I merely showed that 100,000 strings of 9-bytes apiece would fit inside the list box without getting an error. And, you can scroll to any of them on the screen.
    Doctor Ed

  10. #10
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Listbox??!!

    Quote Originally Posted by Code Doc
    He said nothing about accessing any of the information in the list box. Right? I merely showed that 100,000 strings of 9-bytes apiece would fit inside the list box without getting an error. And, you can scroll to any of them on the screen.
    I know but is there point to do that? Common sense, right?

  11. #11
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Listbox??!!

    I'll give you a point for that.

  12. #12
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Listbox??!!

    Rhino said, "I know but is there point to do that? Common sense, right?"
    ------------------------------
    If the elements added to the listbox are an array, you have accress to that array. The list box may then be used for viewing only. In my case, all of the elements were in a sorted array, so accessing the listbox for information that it contained meant nothing because the array was defined in memory.
    Doctor Ed

  13. #13
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Listbox??!!

    Quote Originally Posted by Code Doc
    If the elements added to the listbox are an array, you have accress to that array. The list box may then be used for viewing only. In my case, all of the elements were in a sorted array, so accessing the listbox for information that it contained meant nothing because the array was defined in memory.
    I hope you are not serious but you sound like you are...
    Why do you need to keep in memory two identical arrays? Are you kidding me?

  14. #14
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Listbox??!!

    Rhino asked, "Why do you need to keep in memory two identical arrays? Are you kidding me?"
    --------------------------
    This may be hard for you to believe. My jump sort routine will sort huge arrays faster than a listbox (with the Sorted property turned on) can read unsorted entries into the listbox. I measured this improvement when Ellis Dee was building the Sorting Routines Codebank in May and June of this year.

    So, when working with a huge array, I often jump sort the array first and then add the sorted array elements to a listbox with the Sorted property turned off. Sounds goofy, but it works.

    Now you and Hack have pointed out another potential listbox weakness. When the ListCount exceeds 32,768, the information retrieval from the list is lost beyond that number. So, the sorted listbox somewhat dies at that point, whereas my sorted array hangs onto all the information to the upper bound.
    Doctor Ed

  15. #15

  16. #16
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Listbox??!!

    Rhino asked "And what are you going to do with your array if you cannot access listindex greater than integer using conventional approach?"
    -------------------------------------
    Hmmm. Not sure exactly what you mean. I just built a 100,000-item listbox containing 9-character string entries. I clicked on the list at item 100,000. Although the List1.ListIndex value was invalid, List1.Text was exact in the message box.
    Code:
    Private Sub List1_Click()
    MsgBox "Item " & Str$(List1.ListIndex + 1) & " is " & List1.Text
    End Sub
    So, as long as you don't mind not knowing what the List1.Index value is, the information in the listbox is still there for the taking.
    Doctor Ed

  17. #17
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: Listbox??!!

    and you can always get the list index with a simple one line sendmessage API.

  18. #18

  19. #19
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258

    Re: Listbox??!!

    Instead of

    List_Add(0).AddItem SqlString

    You can use

    Call SendMessage(List_Add(0).hwnd, &H180, 0, ByVal CStr(SqlString))

    This will add to the listbox a item even if the lentgh of the string is greater than 1024.

    Now to read anything use

    Dim sItemText As String * 32000
    Call SendMessage(List_Add(0).hwnd, &H189, 50000, ByVal sItemText)


    This will give you in sItemText the text of the requested index.

    Dont Forget to put the following in your declarations.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width