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!

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

your code is error it say type mismatch! huhuhuhuhuhu please help me!

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..

Ya , rite that is the way to do the program. the code works fine

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

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

finally your so genious qveen72 thanks for this code its work weeeee!

Hi,

Thnx, Mark the Thread as Solved..

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.