Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Avoiding Error:481 Invalid Picture OR How Do I Determine the File Type

Status
Not open for further replies.

Guru2B

Programmer
May 24, 2000
77
GB
Hi,

I am working with pictures (jpegs and gifs) and the links are stored in a DB. When I retrive the name of the image, I also want to load the picture into an imagebox. In the event that the user 'somehow' saved an invalid entry, say a text file in the image filename field, the loadpicture function will generate an error.

ie image1=loadpicture(c:\textfile.txt) <== bad :)

Is there a way to determine the file type of a file? Text vs image. I was thinking that this is a decent way to prevent this problem. If anyone knows of a better solution to this validation/storage problem, I'd be happy to hear about it.

Thanks,
Guru2B
 
I was doing something similar not long ago. Rather than trying to figure out if the file they wanted was good, I just placed an on error BEFORE the load. Since only good photos will load, and non-graphics will error, this seemed to work okay. Of course the PictureError routine simply told them the file was bad/not accessable and then went on about its business. Hope this helps.

On Error GoTo PictureError

If Trim(txtBusinessPhotoPath) > &quot;&quot; Then
Set imgBusiness.Picture = _
LoadPicture(txtBusinessPhotoPath, vbLPLarge, vbLPColor)
Else
Set imgBusiness.Picture = LoadPicture
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top