Problem with turning images invisible on click event.
Hi there, i'm having a problem with what i thought would actually be a pretty simple task. In my form i have an image array containing 9 images with indexes from 0 to 8 inclusively. What i want to happen is when the form is clicked, or when an object is clicked, i want it to do the following:
If the first image in the array is visible, then set it's visibility to false, otherwise, if the first image in the array is not visible, then set the next image in the array's visibility to false. Then if the second image's visiblity is set to false, then set the next image in the array's visibility to false. And so on and so forth.
Basically whats happening is it's a reload function for a game so that when you click, one of 9 images of a bullet is made invisible. Upon the next click, the next image in the sequence's visibility is set to false if the previous image in the sequence's visibility is false.
For some reason i am having a great deal of trouble coding this and so i would appreciate any help!
Re: Problem with turning images invisible on click event.
I think you're overthinking the problem. Just store an internal variable with the number (0-8) of which light should be on. Then, whenever that number needs to be incremented, do the following:
Code:
objImage(lngActiveLight).visible = False
lngActiveLight = lngActiveLight + 1
objImage(lngActiveLight).visible = True 'I may have misread your OP. This line is redundant if all the higher numbered lights are already on.
You may need to add some checks to avoid an error on the first and last lights, but overall this should be a much simpler implementation.
Re: Problem with turning images invisible on click event.
Just code what you are saying inside an inverse For-Next loop
Code:
For I = 8 To 1 Step -1
If Img(I-1).Visible=False Then Img(I).Visible=False
Next I