Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random file selection

Status
Not open for further replies.

crrrazydan

Programmer
Jul 27, 2000
34
US
I am wondering how to, in visual basic, make a program select random files from a directory without me having to list and type every filename.  For example, I want it to load a random image when the user clicks a command buttton.  So if new files are added to the directory, the program will inlclude those too. Does anyone know how to do this?
 
This is the easy way: place a FileList control on your form, set the Visible property to false and set the Pattern property to &quot;*.BMP&quot; (or to whatever image type you want to load). Use this code in the command button:<br><FONT FACE=monospace><b><br>Private Sub Command1_Click()<br>Form1.Picture = LoadPicture(File1.List(Int((File1.ListCount _ + 1) * Rnd + 1)))<br>End Sub<br></font></b><br>It works just as well in a timer control.<br>Have fun. <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
Thanks a lot Alt255.&nbsp;&nbsp;I've been wondering how to do this for quite a while but I couldn't think of how.&nbsp;&nbsp;I though it would probably be something pretty simple too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top