Images

changing picbox images in code

Page 1 of 1

2 Replies - 906 Views - Last Post: 24 March 2010 - 07:09 PM Rate Topic: -----

#1 Java Student  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 481
  • Joined: 05-February 10

Images

Posted 24 March 2010 - 06:25 PM

I need help with this easy problem. Im not going to lie, this is homework and im asking for help.
So im making a SLot Machine.
I need the picture boxes to switch threw the images and here is my code.
Im using the imagelist to hold my 3 images so far (0-2)
 PictureBox1.Image = myImageList.Images(Int(Rnd() * 3)).Image


I get a compiler error, it says the myImageList.Images(Int(Rnd() * 3)).Image expression
does not produce a value?

Also, does Int(Rnd() * 3) return an integer value from 1-3 or 0-2?

This post has been edited by Java Student: 24 March 2010 - 06:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Images

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4358
  • View blog
  • Posts: 12,176
  • Joined: 18-April 07

Re: Images

Posted 24 March 2010 - 06:42 PM

First of all I think you mean CInt, not Int (Even though there are better ways to do this using the convert or tryparse method of the Integer class). That is the reason that it is not producing a value. You want to "C"onvert to an int. Secondly, you don't need .Image on the end, you are referencing images themselves when you use an index in the imagelist. Lastly, test out the range of Cint with Rnd... this is something you can do on your own I think. ;)

Give this a shot...

PictureBox1.Image = myImageList.Images(CInt(Rnd() * 3))



Hope things work out for you. :)

This post has been edited by Martyr2: 24 March 2010 - 06:44 PM

Was This Post Helpful? 0
  • +
  • -

#3 Java Student  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 481
  • Joined: 05-February 10

Re: Images

Posted 24 March 2010 - 07:09 PM

View PostMartyr2, on 24 March 2010 - 05:42 PM, said:

First of all I think you mean CInt, not Int (Even though there are better ways to do this using the convert or tryparse method of the Integer class). That is the reason that it is not producing a value. You want to "C"onvert to an int. Secondly, you don't need .Image on the end, you are referencing images themselves when you use an index in the imagelist. Lastly, test out the range of Cint with Rnd... this is something you can do on your own I think. ;)

Give this a shot...

PictureBox1.Image = myImageList.Images(CInt(Rnd() * 3))



Hope things work out for you. :)


Ah yes it works :sweatdrop:

I knew as computer scientists we count from 0, but every
language is different and im still trying to adjust to
vb syntax.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1