I am fairly new to Xojo. I have a simple routine that copies a file to another location, and checks if the destination file already exists. The code does not work when I run it in the development environment, but it DOES work when I insert a BREAK. I have run it with and without the BREAK, and the code behaves differently. Here is the code:
IF DestinationFile.Exists THEN
SELECT CASE DialogBox (kGraphicCaution, “Desination File Already Exists”, “A file by the same name already exists in the destination folder”, “Do you want to OVERWRITE the existing file, create a NEW COPY, or CANCEL?”, “Overwrite”, “New Copy”, “Cancel”, 3)
CASE 1 ’ Overwrite
IF DestinationFile.LastErrorCode = 0 THEN
IF SourceFile.LastErrorCode = 0 THEN
CALL NoteBox (“Copy Successful”, "I overwrote " + SourceFile.Name + " on " + DestinationFolder.Name)
CALL StopBox (“Copy Failed”, “I successfully deleted the destination file " + DestinationFileName + " but I could not copy the source file to the destination file”, "Error Code " + STR(SourceFile.LastErrorCode))
CALL StopBox (“Copy Failed”, "I could not overwrite the destination file " + DestinationFileName, "Error Code " + STR(DestinationFile.LastErrorCode))
CASE 2 ’ New Copy
CASE 3 ’ Cancel
I have created a condition where the destination file exists and is in use. The code should report “I could not overwrite the destination file”. When the BREAK is not in place, the code passes through the IF statements as if they are all true, and then reports “I overwrote …” even though it clearly did not. When I insert the BREAK where shown, I confirm DestinationFile.LastErrorCode = 102. When I resume from break IT WORKS PROPERLY (sometimes).
What am I doing wrong? Any help will be appreciated.