Click to See Complete Forum and Search --> : It works once and doesn`t work the next time!!!...
Mark1
June 26th, 2001, 04:04 PM
Hi all,
I have two images : Image1 and Image2.
I have two buttons : Button1 and Button2.
The code for button1 is this :
Image1.Picture = Image2.Picture.
This changes the images on the click of the button.
The code for button2 is :
Image2.Picture = Image1.Picture.
This does vice versa.
The problem is, if I think click the first button AGAIN to switch back, nothing happens, the same for button2. How can I fix this?
Mark
Catrina
June 26th, 2001, 04:49 PM
It doesn't work because once you change Image1.picture to Image2.picture, then Image1.picture is the same as Image2.picture, so button2 is working, but you see nothing because Image1.picture is now the same as Image2.picture.
There is no longer a different picture for Image2.picture to change to
Mark1
June 26th, 2001, 05:22 PM
Is there any way I can resolve this then?
Mark
adhimas
June 26th, 2001, 05:28 PM
Store the old picture1 to a temporary place, e.g. a hidden picture box, or a variable of type Picture.
-----------------
Visit: http://www.ezoutliner.com
Mark1
June 26th, 2001, 05:53 PM
I made a copy and stored in it a picture box with visible set to False. I checked the original code and ran again, but it still didn`t work - it only changed once.
Mark
adhimas
June 26th, 2001, 10:31 PM
If you want, I can check out your code. Just tell me what process do you intended to do, and I'll see what I can do. Send your code (or a sample form) and your comments to my email: hening_zz@lycos.com
-----------------
Visit: http://www.ezoutliner.com
Cimperiali
June 27th, 2001, 02:28 AM
Here is an example. You may have to comment two lines to adjust this to your purpouse.
To copy this code: copy and paste to WordPad (not Notepad!).
Then select from WordPad, copy, and paste in VB (Shree suggestion).
option Explicit
Dim oldImg1 as Object
Dim oldImg2 as Object
private Sub Command1_Click()
If Image1.Picture <> Image2.Picture then
Image1.Picture = Image2.Picture
else
Image1.Picture = oldImg1
'do you want the original image2 to be restored too?
'or comment the following line
Image2.Picture = oldImg2
End If
End Sub
private Sub Command2_Click()
If Image1.Picture <> Image2.Picture then
Image2.Picture = Image1.Picture
else
Image2.Picture = oldImg2
'do you want the original image1 to be restored too?
'or comment the following line
Image1.Picture = oldImg1
End If
End Sub
private Sub Form_Load()
set oldImg1 = Image1.Picture
set oldImg2 = Image2.Picture
End Sub
'have fun.
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.