Results 1 to 7 of 7

Thread: [RESOLVED] How Do I Fill ListBox With Infinite FileNames From a Folder?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2008
    Location
    St. John's, Newfoundland, Canada
    Posts
    965

    Resolved [RESOLVED] How Do I Fill ListBox With Infinite FileNames From a Folder?

    I am working on another game show PC game at this moment. One based on the game show Press Your Luck, in fact.

    However, I am now figuring out how to fill the list box with an infinite number of filenames in a folder. Any suggestions?

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How Do I Fill ListBox With Infinite FileNames From a Folder?

    Quote Originally Posted by JonSea31 View Post
    an infinite number of filenames
    You can't be serious!

    What exactly are you trying to do ?

  3. #3
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How Do I Fill ListBox With Infinite FileNames From a Folder?

    Did you, by chance, by infinite mean dynamic/changeable list of files?

    In any case, you can look at the FileListBox control which will show a folders content by itself. If you want to load the list of files through code, I suggest you use a ListView instead (set to Report style, with one or more columns added). ListView is much faster, more flexible, and since it's index is Long integer based it can take over 2 billion items, whereas Listbox with it's Integer based index takes 32767 items, after which the counter gets messed up and indexes start going into negative numbers. Plus listbox is slow and basically just one column.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2008
    Location
    St. John's, Newfoundland, Canada
    Posts
    965

    Re: How Do I Fill ListBox With Infinite FileNames From a Folder?

    When I said "infinite", I don't mean thousands or millions of files. Right now, I have 45 text files in a folder, and I may add some more eventually. If I were to set a max of, say, 250 text files, what would I do?

    EDIT: Just read badger's post - how would I do ListView?

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How Do I Fill ListBox With Infinite FileNames From a Folder?

    For such a small amount of files the FileListBox will do fine. Just set the .Path property to the folder you want it to use and it will automatically load all the files in it. You can also set a mask to "*.txt" for example so it only shows text files. To enforce a limit you could check the ListCount property of the FileListBox, and if it the count is over a certain limit you can do what you want at that point.

    For the ListView you would need to write your own code to load filenames to it, using Dir function, or FileSystemObject to go through all the files in a folder and adding them to the list. But if the count is below a couple of thousand you will be more than fine with FileListBox.

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How Do I Fill ListBox With Infinite FileNames From a Folder?

    When I see this sort of thing I always wonder "Why not just have a button to bring up the Open and/or Save dialog from CommonControls?"

    It really depends on what the point of showing such a file list is, but often it is simply to let users pick a file or files to open. For this sort of thing using a separate dialog saves Form real estate too.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2008
    Location
    St. John's, Newfoundland, Canada
    Posts
    965

    Re: How Do I Fill ListBox With Infinite FileNames From a Folder?

    I figured out the problem myself, with some help from badger. Thanks, folks - this thread is now resolved.

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