About Picture Box in Visual Box Help Please!

Thread Solved

Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

About Picture Box in Visual Box Help Please!

 
0
  #1
Nov 14th, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: About Picture Box in Visual Box Help Please!

 
0
  #2
Nov 14th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: About Picture Box in Visual Box Help Please!

 
0
  #3
Nov 15th, 2008
your code is error it say type mismatch! huhuhuhuhuhu please help me!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 68
Reputation: Rhohitman is an unknown quantity at this point 
Solved Threads: 4
Rhohitman's Avatar
Rhohitman Rhohitman is offline Offline
Junior Poster in Training

Re: About Picture Box in Visual Box Help Please!

 
0
  #4
Nov 15th, 2008
dont just copy the code,match the braces
it is just a code snippet

so use the correct syntax

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdSwitch_click()
  2. if picture1.picture ="D:\hehe\Winter.jpg" then
  3. picture1.picture = LoadPicture("D:\hehe\Sunset.jpg")
  4. else
  5. picture1.picture = LoadPicture("D:\hehe\Winter.jpg")
  6. end sub
also check the button name....i mean ur caption is switch ,so i assumed ur button name to be cmdSwitch..
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: About Picture Box in Visual Box Help Please!

 
0
  #5
Nov 15th, 2008
Ya , rite that is the way to do the program. the code works fine
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: About Picture Box in Visual Box Help Please!

 
0
  #6
Nov 15th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: About Picture Box in Visual Box Help Please!

 
0
  #7
Nov 15th, 2008
Hi,

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

  1. Private Sub Command1_Click()
  2. Static TFlag As Boolean
  3. If TFlag Then
  4. Picture1.Picture = LoadPicture("D:\hehe\Sunset.jpg")
  5. Else
  6. Picture1.Picture = LoadPicture("D:\hehe\Winter.jpg")
  7. End If
  8. TFlag = Not TFlag
  9. End Sub

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

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: About Picture Box in Visual Box Help Please!

 
0
  #8
Nov 15th, 2008
finally your so genious qveen72 thanks for this code its work weeeee!
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: About Picture Box in Visual Box Help Please!

 
0
  #9
Nov 15th, 2008
Hi,

Thnx, Mark the Thread as Solved..

Regards
Veena
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC