Solved

vb6 - Drag n Drop

Posted on 2014-09-26
7
321 Views
Last Modified: 2014-09-28
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 ...

...
 '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
...

Open in new window


MTIA

DWE
0
Comment
Question by:dwe0608
  • 3
  • 3
7 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40348033
Can you attach you project?

What is  MessageBoxx?
0
 
LVL 1

Author Comment

by:dwe0608
ID: 40348078
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 ...
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40348080
Thanks. I'll probably also need to know what website you are getting the files from and how you do that.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 40348226
is bOverwrite true or false at the beginning of loop ?

 if false (or not defined=false) then the first file wont be processed.

 'DroppedItem  is declared as a variant
bOverwrite=true   '<<<added cpde
 For Each DroppedItem In Data.Files

Open in new window

0
 
LVL 1

Author Closing Comment

by:dwe0608
ID: 40348290
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
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40348617
Very nice catch.
0
 
LVL 1

Author Comment

by:dwe0608
ID: 40349042
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.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now