Results 1 to 6 of 6

Thread: [RESOLVED] getting a random file name from a specific folder with VB 2010 express

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    28

    Resolved [RESOLVED] getting a random file name from a specific folder with VB 2010 express

    I can get a file count in the folder and create a random number from that count, but this is all. Sorry I have NO code to attempt this.

  2. #2
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: getting a random file name from a specific folder with VB 2010 express

    GetFiles() returns an array of files. Use your random number to index into that array.

    Alternatively, EnumerateFiles() returns an enumeration, you could count up to your random number and stop there.

    But, considering that the way you count the files is probably to call GetFiles(), it'd be best to reuse that array.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    28

    Re: getting a random file name from a specific folder with VB 2010 express

    How do I set the array size? How do I clear that array each time I've used it?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: getting a random file name from a specific folder with VB 2010 express

    Quote Originally Posted by GMTireman View Post
    How do I set the array size? How do I clear that array each time I've used it?
    You don't set the array size or clear it. You call GetFiles and it returns an array. You can then use the Length of that array as the upper limit when call Random.Next. The sequence of events is:

    Get the files - Directory.GetFiles or DirectoryInfo.GetFiles
    Get the file count - Array.Length
    Generate the random number - Random.Next
    Get the random file - index the array using the random number
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    28

    Re: getting a random file name from a specific folder with VB 2010 express

    ok (?)

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: getting a random file name from a specific folder with VB 2010 express

    Quote Originally Posted by GMTireman View Post
    ok (?)
    purple [~]
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

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