-
Perhaps a simple thing, but..How would one go about using a command button to cycle through ( in this case some pictures). I have photos that I want to diplay using a picture box and want to use a command button to click through them. I am able to dispay the first picture easy enough, using picture1.picture.... but how to display the next photo by clicking the command button a second time /third for the 3rd photo etc...etc . VB6
Thanks in advance
rick
-
Create an Array of strings one element for each picture to display.
load each element with the correct path for the picture
ie PicturePathList[i] = "c:\my_pic1.bmp"
then all you need to do it the following
Code:
Dim StaticCounter As Long
Private Sub cmdNextPic_click()
'' increment the counter
StaticCounter = StaticCounter + 1
'' display the picture
Me.Picture = LoadPicture(PicturePathList[StaticCounter])
'' reset the counter because we are at the last pic?
StaticCounter = StaticCounter Mod Ubound(PicturePathList)
End Sub
you'll probably want to initialize StaticCounter to 0 when you load the form.
-
You shoudl declare it as Private when using it at module level.
Code:
Private StaticCounter As Long
Also, you can load the file list.
Code:
Picture1.Picture = LoadPicture("MyPhoto" & i)
-
Yes! you are correct sir. I should have declared it as Private.
-
Doh... forgot one other thing... initialize the StaticCounter to following instead of 0.
Code:
'' Pre: PicturePathList array has to be initialized
'' before this command.
StaticCounter = LBound(PicturePathList) - 1
;)