A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Arti

806 views · started by Jah ·
#1
Arti
Glad to see you active so ima take advantage on that : P

Dim rndVal As New Random
Dim i As Integer
Dim BGimage(6)
BGimage(0) = Resources.image_1
BGimage(1) = Resources.image_2
BGimage(2) = Resources.image_3
BGimage(3) = Resources.image_4
BGimage(4) = Resources.image_5
BGimage(5) = Resources.image_6
BGimage(6) = Resources.image_7
For i = 0 To 6
Me.BackgroundImage = BGimage(i)
Next

It's only showing me 1 image when i press the button : /
it isn't randomizing.
Thanks !
PS: I know that you are going to move it, but it's the only active section on LG : /
#2
Why would it show a random image? You're not once using that Random variable you declared.

You're setting 7 images, looping from 0 to 6 and updating the background image of one object. It's going to update the background image 7 times, but it's going to happen so fast you're only going to see the last one.
#3
It's for a small bot i'm making for my dad.

Oh, I thought that every time I pressed the button, it would randomize the form background and give me one from the Array list.
#4
It's not going to show a random number if you just iterate through 1 to 7...
I haven't used .NET in years, but try this:

Dim rndVal As New Random(System.DateTime.Now.Millisecond)
Dim i As Integer
Dim BGimage(6)
BGimage(0) = Resources.image_1
BGimage(1) = Resources.image_2
BGimage(2) = Resources.image_3
BGimage(3) = Resources.image_4
BGimage(4) = Resources.image_5
BGimage(5) = Resources.image_6
BGimage(6) = Resources.image_7
Me.BackgroundImage = BGimage(rndVal.Next(0,6))
#5
Artificial wrote:
It's not going to show a random number if you just iterate through 1 to 7...
I haven't used .NET in years, but try this:

Dim rndVal As New Random(System.DateTime.Now.Millisecond)
Dim i As Integer
Dim BGimage(6)
BGimage(0) = Resources.image_1
BGimage(1) = Resources.image_2
BGimage(2) = Resources.image_3
BGimage(3) = Resources.image_4
BGimage(4) = Resources.image_5
BGimage(5) = Resources.image_6
BGimage(6) = Resources.image_7
Me.BackgroundImage = BGimage(rndVal.Next(0,6))

Works perfectly , Thanks bro.
Also, what if i wanted to change every 20 Seconds ?
#6
You would call the function you created every 20 seconds wherever the call clause might be, from what I surmise. You could do this via Timer by updating the interval, or using threads (probably overkill) or a related avenue (looping would probably work as well).
#7
Good idea, I didn't think of loops, thanks.