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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random files from My.Resources

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,548
US
VB.NET 2010

I have My.Resources with several images (jpg files): IMG01.JPG, IMG02.JPG, ... IMG15.JPG

I can show an image in the picture box on my Splash form, no problem with:
[tt]
PictureBox1.Image = My.Resources.IMG15
[/tt]
How can I randomly pick one out of 15 images I have from my Resources?

I know how to pick a random number and I know how to format it to be 01, 02, etc, but if I do something like:
[tt]
PictureBox1.Image = My.Resources.IMG[blue] & MyRndNo[/blue]
[/tt]
it doesn't recognize the variable.

Have fun.

---- Andy
 

Load the image resources into an ImageList, then access them by randomly selected index.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 

That sounds like a little over-kill to go after all images if I only need one :-(

Any idea how to go after / loop thru all (jpg) files in Resource?

Have fun.

---- Andy
 
Andy, what if you put the 15 image names in an array:

image(0) = My.Resources.IMG01
image(1) = My.Resources.IMG02
etc...

then pick a random number, then

PictureBox1 = image(randomnumber)

I didn't test this, as I am at work with no VS, but the theory looks good :)



Cheers,

Realm174
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top