Need some assistance using the MessageBox YesNoCancel buttons. I'm trying to check and see if a file exists, if it does, then prompt the user to select yes to overwrite, select no, and the file will copy to another location, or select cancel and close the dialog. My code I have below, goes to the "YES" statement no matter if I press Yes, No or Cancel. Any help is appreciated!!!
Thanks.
Code:Private Function FileExists(ByVal oldname, ByVal newname) If File.Exists(oldname) Then If File.Exists(newname) Then MessageBox.Show("File" & newname & " already exists. Do you wish to overwrite?", "File Exists", _ MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If Windows.Forms.DialogResult.Yes Then My.Computer.FileSystem.CopyFile(oldname, newname, True) ElseIf Windows.Forms.DialogResult.No Then File.Copy(oldname, "s:\pfirs\joann\" & oldname) Else 'Windows.Forms.DialogResult.Cancel() Me.Close() End If Else My.Computer.FileSystem.CopyFile(oldname, newname, True) End If




Reply With Quote