dwe0608
asked on
vb6 - Drag n Drop
Hi guys,
The following code has a peculiarity I cannot work out - perhaps its simply because I am very tired but for the life of me I cannot work it out. The code is from a Drag Drop event - I catch the data object which is filled with files from dragging them from explorer.
the function this code is in works fine except the peculiarity - it leaves one file behind on every ocassion ... I know I can loop through the files in other ways, but I want to understand why it leaves one file behind ...
MTIA
DWE
The following code has a peculiarity I cannot work out - perhaps its simply because I am very tired but for the life of me I cannot work it out. The code is from a Drag Drop event - I catch the data object which is filled with files from dragging them from explorer.
the function this code is in works fine except the peculiarity - it leaves one file behind on every ocassion ... I know I can loop through the files in other ways, but I want to understand why it leaves one file behind ...
...
'DroppedItem is decalred as a variant
For Each DroppedItem In Data.Files
DoEvents 'During long loops its always a good idea to return control to windows
Debug.Print "Shift = " & Shift & " - " & DroppedItem
pbFiles.Value = pbFiles.Value + 1
DoEvents
If fso.FileExists(DroppedItem) Then
' test to see if the file exists
sFileName = fso.GetFileName(CStr(DroppedItem))
If fso.FileExists(defDir & sFileName) Then
' we exist
' let the user decide if we over write or not
Select Case MessageBoxx(Me, sFileName & " exists in the destination directory. Do you want to over write it? If you're unsure select Cancel and check your files.", vbExclamation + vbYesNoCancel)
Case vbYes
' delete the file already there
kill defDir & sFileName
bOverwrite = True
Case vbNo
bOverwrite = False
Case vbCancel
Exit Sub
End Select
End If
If Shift = 1 Then
If bOverwrite Then fso.MoveFile DroppedItem, defDir
Else
If bOverwrite Then fso.CopyFile DroppedItem, defDir, bOverwrite
End If
ElseIf fso.FolderExists(DroppedItem) Then
If Shift = 1 Then
fso.MoveFolder DroppedItem, defDir
Else
fso.CopyFolder DroppedItem, defDir
End If
End If
DoEvents
bOverwrite = True
Next
...
MTIA
DWE
ASKER
Hi Martin
I'll hive off a seperate project and post
Messageboxx is a custom msgbox function which is subclassed so I can center it on the parent window ... I'll include it in the project ...
I'll hive off a seperate project and post
Messageboxx is a custom msgbox function which is subclassed so I can center it on the parent window ... I'll include it in the project ...
Thanks. I'll probably also need to know what website you are getting the files from and how you do that.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Robberbaron - well, I did say I was tired. .... you were correct ... it tested for false on the first loop as you said and it didnt change until the 2nd item ....
Thank you ...
Regards
Darrin
Thank you ...
Regards
Darrin
Very nice catch.
ASKER
Hi Martin - I said I'd post the project and here it is - while RobR picked the error the project is still worthwhile having here because of a couple of unique functions in the code - first is the ablity to drag and move or copy the files - second is the ability to center the BrowseForFolder dialog over the calling window and lastly the ability to center the messagebox on the calling window. There is also a usercontrol in it which is a progressbar with a caption and percentage - not all of this is my work but I know that some people might find it useful ...
I've tried to upload the file but because of the usercontrol in the zip file its disallowed. I have put it on GoogleDrive for downloading here.
Any comments would be welcomed.
I've tried to upload the file but because of the usercontrol in the zip file its disallowed. I have put it on GoogleDrive for downloading here.
Any comments would be welcomed.
What is MessageBoxx?