Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am changing picture as combobox is selected. Picture name is saved as per index in combobox. I want to display a defaul picturt and picture is not found in folder / source.

Can you please assist.

Below is the coding I am using to upload the picture in vb6

Picture2.Picture = LoadPicture(App.Path & "\" & Combo1.Text & ".jpg")
Posted

I think, if you do it like this, your System throws an Exeption if there is no Picture to be loaded. In this case you only have to catch the Exeption and set the Picture2.Picture to your favourized Default-Picture ...
 
Share this answer
 
Comments
hypermellow 20-May-15 4:24am    
Hi, do you realise this question is tagged as a VB6 question?

With VB6 you can't catch exceptions ... you may only raise, trap, and then handle errors.
Hi,

Have a look at the FileSystemObject[^] found in the scripting runtime object (SCRRUN.DLL).

This will provide you the means to check if the image file exists, and then set your default image if it does not.

After you've setup your project reference to the scripting runtime(see the link above), something like this should be what you're looking for:

VB
Dim oFso As New Scripting.FileSystemObject

If(oFso.FileExists(App.Path & "\" & Combo1.Text & ".jpg") Then
    Picture2.Picture = LoadPicture(App.Path & "\" & Combo1.Text & ".jpg") 
Else
    Picture2.Picture = LoadPicture(App.Path & "\defaultImage.jpg") 
End If


... hope it helps.
 
Share this answer
 
Comments
Gaus Shaikh 20-May-15 4:25am    
THanks. Its really helpfull. Can we disable the picture box if no image is found instead of loading default image
hypermellow 20-May-15 4:40am    
Hi, I don't think the picture box control has an enabled/disabled or a visible property. You could pass LoadPicture an empty string and the picture box will be cleared, and not display any image. Something like:
Picture2.Picture = LoadPicture("")
Gaus Shaikh 20-May-15 8:48am    
I am getting an error as user define type is not define
hypermellow 20-May-15 8:54am    
... I think you forgot to add a reference to the Microsoft Scripting Runtime object.

Look at step 2 in this link for how to add the reference:
https://support.microsoft.com/en-us/kb/186118

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900