On Error?

Lanc1988

Well-known member
Joined
Nov 27, 2003
Messages
508
I have a button that when clicked copies a image to the users desktop.. but if a image with that name already exists I need it to show a message box and say "Image could not be copied to desktop because it already exists"

I know how to make the message box appear but whats the code for On Error? I tried On Error Resume Next but that does nothing to do what I want it to do.
 
You dont need to trap an error (and even if you really did, forget On Error and go for Try...Catch):

If System.IO.File.Exists("C:\theFile.txt") Then
MessageBox.Show("yourMsg")
End If
 
ok.. that works, but now what do I put around my other code if it doesnt exist? Because I have a message box pop up there also and say that the image has been copied to desktop.

EDIT: or maybe theres some code to say IF doesnt exist or something.
 
If System.IO.File.Exists("C:\theFile.txt") Then
MessageBox.Show("yourMsg")
Else
-File does not exist; do what you have to here...
-To copy the file, read up on System.IO.File.Copy()
End If
 
Back
Top