this is my first project n i need help in displaying images in imagebox

this is the code to display the code which i am using to display images in imagebox

Image1.Picture = LoadPicture("C:\images\" & Text3.Text & ".jpg") '<<this works fine>>

in the above code the location is C:\images\ , the file name will be the value of text3

but in case if the image with the filename<<value of text 3>> is nt found in C:\images\

i want to display an alternate image whose name is "mypic" and is located in C:\images\

what should be the code??
plz help ASAP

Recommended Answers

All 12 Replies

Dim basePath as String
Dim filename as String
Dim ext as String
ext = ".jpg"

basePath = "C:\Images\"
filename = Text3.Text
filename = filename & ext

 Dim oFile As New Scripting.FileSystemObject
    FileExists = oFile.FileExists(basePath & filename + ext)

If(!FileExists)
filename = "mypic" + ext
End If

Image1.Picture = LoadPicture(basepath & filename)
If(!FileExists)

I'm not sure but ...
IS THIS VB6 ???????????

nice catch, got in a hurry and have been used to c# for a bit

you do need to add a reference to scrrun.dll

If Not (oFile.FileExists(basePath & filename + ext)) Then
filename = "mypic" + ext
End If

Dim oFile As New Scripting.FileSystemObject

when running it says " compile error: user -defined type not defined

plz help me with this...ASAP

add reference to scrrun.dll

i really dont knw how to reference to scrrun.dll

plz tell me how it is done

sumting is wrong with the code..it not working ...pls recheck the code

my bad, substitute the '+' with '&'

sorry for the last post....it was my mistake that it wasnt working...no its working fine...

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.