Thursday, November 18, 2010

Setting a picture box to change pictures with a timer in Visual Basic?

My assignment is to make a slot machine, I have done everything except make the pictures %26quot;spin%26quot; I wanted to do something like randomly show pictures in a picture box but I am unsure about how to set it up. I have 10 pictures in my resources and 15 picture boxes. I wanted to set the time so when you pushed the spin button the first row would move fast and the second row a little slower and so on. Any help would be greatly appreciated!Setting a picture box to change pictures with a timer in Visual Basic?
*I am still editing this post...



First, find the function that generates a random number. You will be using it to generate a number UP TO the number of images in your resource.



Add a timer and set the timer duration to about 200 at first. Then, slowly lower it about 10 at a time to find a speed you like.



*This is just a rough idea what it might look like...



----------------------------

Dim Delayer As Long=1



Sub Timer1 Tick



If Delayer %26gt;0 Then PictureBox1.Picture=Resource( RandomNumber )



If Delayer %26gt;1 Then PictureBox2.Picture=Resource( RandomNumber )



If Delayer %26gt;2 Then PictureBox3.Picture=Resource( RandomNumber )



If Delayer %26gt;15 Then

Delayer=1

Else

Delayer+=1

End If



End Sub





------------------



The delayer adds one in each tick of the timer. Each picture box changed only after the delayer number reaches a point, causing the delay. For example, since the first picture triggers so long as the delayer number is %26gt; 0, it will change every time.



If you want truly different spin speeds, use a different timer for each picture box. You can create timers in code, or just drop the controls on the form.



Ahh, im tired with a crying infant at 5 AM, so my thinking process is not that clear.

No comments:

Post a Comment