Computing.Net > Forums > Programming > VB random filename from directory

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VB random filename from directory

Reply to Message Icon

Original Message
Name: jamesc
Date: January 15, 2006 at 04:09:19 Pacific
Subject: VB random filename from directory
Comment:

In VB i want to get a random file name for all bmp/jpeg/png (only) files from a specified directory ("c:\pics") and store it as a variable. Any ideas?



Report Offensive Message For Removal


Response Number 1
Name: StuartS
Date: January 16, 2006 at 01:51:30 Pacific
Reply: (edit)

Use the file list box to get a list of files in the directory. Then use the Rnd function to select one of them

Int((File(index)* Rnd )

Will return a number between Zero and the maximum number of files in the list.

Stuart


Report Offensive Follow Up For Removal

Response Number 2
Name: jamesc
Date: January 17, 2006 at 13:23:56 Pacific
Reply: (edit)

That doesnt work. (Even after i add the extra bracket).

I have a list stored in an array called 'files' now. All i wanna do is copy a random item from that array into a variable. Can i use Rnd to select an item via it's index and copy it into the variable? Anyone?


Report Offensive Follow Up For Removal

Response Number 3
Name: StuartS
Date: January 17, 2006 at 23:22:45 Pacific
Reply: (edit)

Look in the help Files for the Rnd function and it will tell you how to use it.

Stuart


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software