DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   About Picture Box in Visual Box Help Please! (http://www.daniweb.com/forums/thread157326.html)

ryan311 Nov 14th, 2008 10:12 am
About Picture Box in Visual Box Help Please!
 
im beginner in visual basic can anyone help me please?
i have 1 command botton and 1 picturebox
my command button name is Switch
every time i click my command button Switch the image in the picturebox change
for example i have already an image in the picturebox Sunset image
if i click my command Button the image change to Winter
if i click once again my command button the image should change to Sunset
if i click it again the image should Winter in the picture box

heres my code in form load

Private Sub Form_Load()
picture1.picture = LoadPicture("D:\hehe\Winter.jpg"
End Sub

please help me badly needed! god bless you daniweb and more power!

arghasen Nov 14th, 2008 6:44 pm
Re: About Picture Box in Visual Box Help Please!
 
u try the code snippet:
Private Sub cmdSwitch_click()
if picture1.picture ="D:\hehe\Winter.jpg" then
picture1.picture = LoadPicture("D:\hehe\Sunset.jpg"
else
picture1.picture = LoadPicture("D:\hehe\Winter.jpg"
end sub

this would do for switch
similarly for the pictue click change in picture write the same code in the picture1_click event...
this should solve ur problem

ryan311 Nov 15th, 2008 2:42 am
Re: About Picture Box in Visual Box Help Please!
 
your code is error it say type mismatch! huhuhuhuhuhu please help me!

Rhohitman Nov 15th, 2008 3:58 am
Re: About Picture Box in Visual Box Help Please!
 
dont just copy the code,match the braces
it is just a code snippet

so use the correct syntax

Private Sub cmdSwitch_click()
if picture1.picture ="D:\hehe\Winter.jpg" then
picture1.picture = LoadPicture("D:\hehe\Sunset.jpg")
else
picture1.picture = LoadPicture("D:\hehe\Winter.jpg")
end sub
also check the button name....i mean ur caption is switch ,so i assumed ur button name to be cmdSwitch..

arghasen Nov 15th, 2008 4:28 am
Re: About Picture Box in Visual Box Help Please!
 
Ya , rite that is the way to do the program. the code works fine

ryan311 Nov 15th, 2008 5:35 am
Re: About Picture Box in Visual Box Help Please!
 
the error is type mismatch that is the code i put in my command button still got error type mismatch

here's my code in my command button:

Private Sub Command1_Click()
If Picture1.Picture = "D:\hehe\Winter.jpg" Then
Picture1.Picture = LoadPicture("D:\hehe\Sunset.jpg")
Else
Picture1.Picture = LoadPicture("D:\hehe\Winter.jpg")
End If
End Sub

still not work huhuhu

QVeen72 Nov 15th, 2008 6:04 am
Re: About Picture Box in Visual Box Help Please!
 
Hi,

Its always Better to Keep a Static Boolean Variable in such cases...
Try this :

Private Sub Command1_Click()
    Static TFlag As Boolean
    If TFlag Then
        Picture1.Picture = LoadPicture("D:\hehe\Sunset.jpg")
    Else
        Picture1.Picture = LoadPicture("D:\hehe\Winter.jpg")
    End If
    TFlag = Not TFlag
End Sub

Static Variables are Variables declared within the Procedure and retain their values as long as the code is running

Regards
Veena

ryan311 Nov 15th, 2008 6:06 am
Re: About Picture Box in Visual Box Help Please!
 
finally your so genious qveen72 thanks for this code its work weeeee!

QVeen72 Nov 15th, 2008 6:11 am
Re: About Picture Box in Visual Box Help Please!
 
Hi,

Thnx, Mark the Thread as Solved..

Regards
Veena


All times are GMT -4. The time now is 3:49 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC