473,842 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to drag drop file/s into a textbox from winexplorer?

43 New Member
Hello , I'm trying to drag drop file/s into a textbox from windows explorer using vb6. I can't figure it out how to create textboxes at runtime depending on how many file selection did I make for dragdrop purposes. Is there a way to do that in vb6 and how?

Thanks alot and happy holidays.
Dec 22 '10
64 9730
blurryanthem
43 New Member
I did try to replicate thousand files a while ago to my destination drive and I was thinking that a progress indicator should also be added while copy/replication in progress to guide user that tool has not hanged or anything before replication confirmation is displayed. Any idea how?
Jan 6 '11 #41
Guido Geurs
767 Recognized Expert Contributor
Sorry for the confusion.
No this is not a new button but a peace of code to place before the code in the 'Copy' command to check if the folder exist.
I have renamed the elements in my code.
Please tell me if there are still names not conform with Yours, so I can rename them in my code and prevent confusions in the future. (see attachment)
I have also added a simple gouge to indicate the progress of copying.
To add or modify the foldername in the textbox, just set the textbox enabled=true

PS:
There was an error in previous code for checking the folders existence, it must be:
Expand|Select|Wrap|Line Numbers
  1.    If Dir$(SaveTo.Text, vbDirectory) = "" Then
Jan 7 '11 #42
blurryanthem
43 New Member
Sir Geur,

I've been working on the LogBtn. It was able to create a text file already, where I could also write the directory file list from my destination folder. However it was only able to write 1 copied file :(

This is the code.

Expand|Select|Wrap|Line Numbers
  1. Private Sub LogBtn_Click()
  2.     Dim A As String
  3.  
  4.     A = Dir$(SaveTo & "*.*", vbDirectory)
  5.     Open "c:\File List.txt" For Output As #1
  6.     Write #1, A
  7.     Close #1
  8.  
  9. End Sub
  10.  
Thanks!
Jan 7 '11 #43
blurryanthem
43 New Member
Sir Geur,

I have already tried your code on creating new folder in a directory and it works good now.

However, I think I messed up with some of my error handling.. they are not working as expected.

In my replicate/duplicate button I need alot of file handling checking like:

1. "No file to replicate." - if user clicks replicate button but has not dragged any file yet a message should be prompted.

2. If file exist: File xx exist - replace file?
a. Yes - resume copy process
b. No - exit condition

( I don't know where should that reside in my file checking condition). I choose the vbOKCancel so that if OK is clicked ( an answer to replace existing file question ), the copy process will resume.. but if Cancel is clicked it will just exit the sub.

Expand|Select|Wrap|Line Numbers
  1. For STARTFILEidx = 1 To Text1.Count - 1
  2.       '§ find FILENAME (NAME + EXTENTION)
  3.       FILENAME = Mid(Text1(STARTFILEidx), InStrRev(Text1(STARTFILEidx), "\") + 1)
  4.       '§ find NAME
  5.       NAME = Left(FILENAME, InStrRev(FILENAME, ".") - 1)
  6.       '§ find EXTENTION
  7.       EXTENTION = Mid(FILENAME, InStrRev(FILENAME, ".") + 1)
  8.          '§ Make copies
  9.          For FILEidx = 1 To Val(CopyTimes(STARTFILEidx).Text)
  10.             FILETO = NAME & "(" & FILEidx & ")" & "." & EXTENTION
  11.             If Dir(SaveTo.Text & "\" & FILETO) <> "" Then
  12.                MESSAGE = MsgBox(FILETO & " already exist." & _
  13.                      vbNewLine & "Replace existing file ?", vbOKCancel)
  14.                'LabelProgress.Caption = "Progress"
  15.                Exit Sub
  16.             End If
  17.             FileCopy Text1(STARTFILEidx), SaveTo.Text & "\" & FILETO
  18.             COPIESMADE = COPIESMADE + 1
  19.             LabelProgress.Caption = "Copy Progress: COPIESMADE & " / " & NMBRCOPIES"
  20.             ShapeProgress.Width = (COPIESMADE / NMBRCOPIES) * ShapeProgressBack.Width
  21.             LOGTEXT = LOGTEXT & FILETO & vbNewLine '§ add filename for printing log
  22.           Next
  23.     LabelProgress.Caption = "Files successfully replicated."
  24.     ShapeProgress.Width = 0
  25. Next
  26. FileError:
  27.             Select Case Err.Number
  28.  
  29.             Case 61
  30.             MsgBox ("Destination drive is full.")
  31.  
  32.             Case 70
  33.             MsgBox ("Permission Denied. The Memory Device is write protected.")
  34.  
  35.             Case 71
  36.             MsgBox ("Destination drive not available.")
  37.             End Select
  38.     '§ print Log
  39.  
3. I haven't got any idea on how to work with my Log Button yet.. it only prints 1 file
Expand|Select|Wrap|Line Numbers
  1. Private Sub LogBtn_Click()
  2.     Dim A As String
  3.  
  4.     A = Dir$(SaveTo & "*.*", vbDirectory)
  5.     Open "c:\File List.txt" For Output As #1
  6.     Write #1, A
  7.     Close #1
  8.  
  9. End Sub
  10.  
Thank you!
Jan 11 '11 #44
blurryanthem
43 New Member
Hello Sir Geur,

I think I got the code working already for my item 2. ( File exist, vbOKCancel ). Here's my code:

Expand|Select|Wrap|Line Numbers
  1. For STARTFILEidx = 1 To Text1.Count - 1
  2.       '§ find FILENAME (NAME + EXTENTION)
  3.       FILENAME = Mid(Text1(STARTFILEidx), InStrRev(Text1(STARTFILEidx), "\") + 1)
  4.       '§ find NAME
  5.       NAME = Left(FILENAME, InStrRev(FILENAME, ".") - 1)
  6.       '§ find EXTENTION
  7.       EXTENTION = Mid(FILENAME, InStrRev(FILENAME, ".") + 1)
  8.          '§ Make copies
  9.          For FILEidx = 1 To Val(CopyTimes(STARTFILEidx).Text)
  10.             FILETO = NAME & "(" & FILEidx & ")" & "." & EXTENTION
  11.             If Dir(SaveTo.Text & "\" & FILETO) <> "" Then
  12.                MESSAGE = MsgBox(FILETO & " already exist." & _
  13.                      vbNewLine & "Replace existing file ?", vbOKCancel)
  14.                'LabelProgress.Caption = "Progress"
  15.  
  16.                 If MESSAGE = vbOK Then
  17.                 FileCopy Text1(STARTFILEidx), SaveTo.Text & "\" & FILETO
  18.                 COPIESMADE = COPIESMADE + 1
  19.                 LabelProgress.Caption = "Copy Progress:" & COPIESMADE & " / " & NMBRCOPIES & ""
  20.                 ShapeProgress.Width = (COPIESMADE / NMBRCOPIES) * ShapeProgressBack.Width
  21.                 LOGTEXT = LOGTEXT & FILETO & vbNewLine '§ add filename for printing log
  22.                 Else
  23.                 Exit Sub
  24.                 End If
  25.  
  26.             End If
  27.                 FileCopy Text1(STARTFILEidx), SaveTo.Text & "\" & FILETO
  28.                 COPIESMADE = COPIESMADE + 1
  29.                 LabelProgress.Caption = "Copy Progress:" & COPIESMADE & " / " & NMBRCOPIES & ""
  30.                 ShapeProgress.Width = (COPIESMADE / NMBRCOPIES) * ShapeProgressBack.Width
  31.                 LOGTEXT = LOGTEXT & FILETO & vbNewLine '§ add filename for printing log
  32.           Next
  33.             LabelProgress.Caption = "Files successfully replicated."
  34.             ShapeProgress.Width = 0
  35.  
I hope you could help me with the issue 1 and 3.

Thanks!
Jan 11 '11 #45
Guido Geurs
767 Recognized Expert Contributor
Q1 = If there is only 1 textbox with filenames (the original with index=0 ) then there are no copies: so no files dropped.
Place this code at the beginning of the command code:

Expand|Select|Wrap|Line Numbers
  1. '§ check if Files to copy <> 0
  2.    If TextFiles.Count = 1 Then
  3.       MsgBox "There are no files to copy !" & vbNewLine & _
  4.                "Please, drop files into the Dropzone !"
  5.       Exit Sub
  6.    End If
Q2 = I have also added the possibility if the user just not want to uverwrite this one file.
The program continues with the next file.
Expand|Select|Wrap|Line Numbers
  1.          '§ Make copies
  2.          For FILEidx = 1 To Val(CopyTimes(STARTFILEidx).Text)
  3.             FILETO = NAME & "(" & FILEidx & ")" & "." & EXTENTION
  4.             If Dir(SaveTo.Text & "\" & FILETO) <> "" Then _
  5.                MESSAGE = MsgBox("The file " & FILETO & " exist !" & vbNewLine & _
  6.                         "Replace ? [Yes]" & vbNewLine & _
  7.                         "No for only this one [No]" & vbNewLine & _
  8.                         "Cancel All [Cancel]", vbYesNoCancel)
  9.             If MESSAGE = vbCancel Then Exit Sub
  10.             If MESSAGE = vbNo Then
  11.                NMBRCOPIES = NMBRCOPIES - 1
  12.                GoTo NextFile
  13.             End If
  14.             FileCopy TextFiles(STARTFILEidx), SaveTo.Text & "\" & FILETO
  15.             COPIESMADE = COPIESMADE + 1
  16.             LabelProgress.Caption = "Progress : " & COPIESMADE & "/" & NMBRCOPIES & " copy-ed"
  17.             ShapeProgress.Width = (COPIESMADE / NMBRCOPIES) * ShapeProgressBack.Width
  18.             LOGTEXT = LOGTEXT & FILETO & vbNewLine '§ add filename for printing log
  19. NextFile:
  20.          Next
  21.    Next
Q3 = In the copy code is also added a var LOGTEXT(string)
which keep track of the copied files.
Just dump this data in a textfile with:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ComSaveLog_Click()
  2. Dim MESSAGE As Variant
  3. Dim OUTPUTFN As Integer
  4.    If Dir(SaveTo.Text & "\Log.txt") <> "" Then _
  5.       MESSAGE = MsgBox("The file Log.txt exist !" & vbNewLine & "Overwrite ?", vbOKCancel)
  6.    If MESSAGE = vbCancel Then Exit Sub
  7.    OUTPUTFN = FreeFile
  8.    On Error GoTo ErrWriting
  9.    Open SaveTo.Text & "\Log.txt" For Output As #OUTPUTFN
  10.       Print #OUTPUTFN, LOGTEXT
  11.    Close #OUTPUTFN
  12. Exit Sub
  13. ErrWriting:
  14.    Close #OUTPUTFN
  15.    MsgBox ("There is an error writing the settings file !")
  16. End Sub
Jan 12 '11 #46
blurryanthem
43 New Member
Sir Geur,

I have added these codes to handle the ff error trapping..let me know if the codes are fine:

a. '§ Opens Saved Log file (Replicate button )
Expand|Select|Wrap|Line Numbers
  1. Private Sub LogBtn_Click()
  2.     Dim LogFile As String
  3.     LogFile = "notepad c:\Log.txt"
  4.     Shell LogFile
  5. End Sub
  6.  
b. If file exists ( replace Ok/Cancel)
Expand|Select|Wrap|Line Numbers
  1. '§ Loop through files to copy
  2.    COPIESMADE = 0
  3.    'LabelProgress.Caption = "Copy Progress"
  4.  
  5. For STARTFILEidx = 1 To Text1.Count - 1
  6.       '§ find FILENAME (NAME + EXTENTION)
  7.       FILENAME = Mid(Text1(STARTFILEidx), InStrRev(Text1(STARTFILEidx), "\") + 1)
  8.       '§ find NAME
  9.       NAME = Left(FILENAME, InStrRev(FILENAME, ".") - 1)
  10.       '§ find EXTENTION
  11.       EXTENTION = Mid(FILENAME, InStrRev(FILENAME, ".") + 1)
  12.          '§ Make copies
  13.          For FILEidx = 1 To Val(CopyTimes(STARTFILEidx).Text)
  14.             FILETO = NAME & "(" & FILEidx & ")" & "." & EXTENTION
  15.             If Dir(SaveTo.Text & "\" & FILETO) <> "" Then
  16.                MESSAGE = MsgBox(FILETO & " already exist." & _
  17.                      vbNewLine & "Replace existing file ?", vbOKCancel)
  18.                'LabelProgress.Caption = "Progress"
  19.  
  20.                 If MESSAGE = vbOK Then
  21.                 FileCopy Text1(STARTFILEidx), SaveTo.Text & "\" & FILETO
  22.                 COPIESMADE = COPIESMADE + 1
  23.                 LabelProgress.Caption = "Copy Progress:" & COPIESMADE & " / " & NMBRCOPIES & ""
  24.                 ShapeProgress.Width = (COPIESMADE / NMBRCOPIES) * ShapeProgressBack.Width
  25.                 LOGTEXT = LOGTEXT & FILETO & vbNewLine '§ add filename for printing log
  26.                 Else
  27.                 Exit Sub
  28.                 End If
  29.  
  30.             End If
  31.                 FileCopy Text1(STARTFILEidx), SaveTo.Text & "\" & FILETO
  32.                 COPIESMADE = COPIESMADE + 1
  33.                 LabelProgress.Caption = "Copy Progress:" & COPIESMADE & " / " & NMBRCOPIES & ""
  34.                 ShapeProgress.Width = (COPIESMADE / NMBRCOPIES) * ShapeProgressBack.Width
  35.                 LOGTEXT = LOGTEXT & FILETO & vbNewLine '§ add filename for printing log
  36.           Next
  37.             LabelProgress.Caption = "Files successfully replicated."
  38.             ShapeProgress.Width = 0
  39.  
  40.             '§ print Log
  41.             sFilename = "c:\Log.txt"
  42.  
  43.             'obtain the next free file handle from the
  44.             'system and and save the text box contents
  45.             hFile = FreeFile
  46.             Open sFilename For Output As #hFile
  47.             Print #hFile, LOGTEXT
  48.             Close #hFile
  49.  
c. No copy destination ( if SaveTo.Text has no value )
Expand|Select|Wrap|Line Numbers
  1.  , if replicate button is pressed
  2. If SaveTo.Text = "" Then
  3.       MsgBox ("Please specify a copy destination.")
  4. End If
  5.  
d. I don't have error handling yet to check if there are no chosen/dragged files when replicate button is pressed.
Jan 12 '11 #47
Guido Geurs
767 Recognized Expert Contributor
Seems to be OK.
You can define how the Notepad window must be opened by:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ComShowLog_Click()
  2. Dim NOTEPADSHELL As Double
  3.    NOTEPADSHELL = Shell("Notepad " & SaveTo.Text & "\Log.txt", vbNormalFocus)
  4. End Sub
No need to proceed with the code if there is no destination folder (exit sub) so the code can be:

Expand|Select|Wrap|Line Numbers
  1. ....
  2. '§ check if Files to copy <> 0
  3.    If TextFiles.Count = 1 Then '§ only the original textbox with index=0
  4.       MsgBox "There are no files to copy !" & vbNewLine & _
  5.                "Please, drop files into the Dropzone !"
  6.       Exit Sub
  7.    End If
  8. ....
Jan 12 '11 #48
blurryanthem
43 New Member
a. I think I have to consider your suggestions with the conditions if a file already exist.

"Replace ? [Yes]" & vbNewLine & _
"No for only this one [No]" & vbNewLine & _
"Cancel All [Cancel]", vbYesNoCancel)

Thanks for the idea.

b. I have already added the checking for "No file to replicate." and it worked already.
Jan 12 '11 #49
blurryanthem
43 New Member
Hello Sir Geur,

I modified your code a bit in the situation wherein no destination drive is specified, since program was still able to continue with the code instead of exiting the sub and copies the files at root of c:\

Expand|Select|Wrap|Line Numbers
  1. '§ check if Files to copy <> 0
  2.     If TextFiles.Count = 1 Then '§ only the original textbox with index=0
  3.        MsgBox "There are no files to copy !" & vbNewLine & _
  4.                 "Please, drop files into the Dropzone !"
  5.        Exit Sub
  6.     End If
  7.  
Modified code. ( This already works, and exits the sub.no copy process is performed )

Expand|Select|Wrap|Line Numbers
  1. If Text1.Count = 1 Then
  2.        MsgBox "There are no files to copy." & vbNewLine & _
  3.                 "Please, drop files into the drop zone."
  4.     Else
  5.     Exit Sub
  6. End If
  7.  
Thanks!
Jan 13 '11 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1918
by: Oleg Medyanik | last post by:
Hi, Is there any way to drag-drop messages from Outlook 2003 into my Application (.NET based) I have not found it googling yet. The problem is that i want the messages to preserve their MSG format, not just get their text. (it should look like you've dropped message to MS Word). Any help is appreciated. Thanks you
2
4339
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put there? What about Drag/Drop; is there more than one way for the source to make data available Is it always OLE?
1
1678
by: Marco Zender | last post by:
Hello, i'm in real trouble and don't know how to handle it! May someone can give me a hint? Following problem: In my application you can drag&drop a file from the explorer. In my application this file will be encrypted and then you should be able to drag&drop the file from the application to the explorer. How can i code the last step ?!? I have tried it with DoDragDrop but without success :-( TIA
5
10170
by: Brian Henry | last post by:
I haven't worked much with drag/drop but I am trying to make a form that accepts files to drug onto it from explorer and droped and have the form know the full path and file name of the files dropped onto it.. does anyone have any examples of this? thanks
0
1782
by: Pesso | last post by:
I'm loading a text file to a RichTextBox control to drag a selection of a text and drop it into a tree view control. It works except after the drag and drop operation the RichTextBox scrolls to the top. This is very inconvenient because after the drag-drop operation the user has to scroll down to where he was before. Is there anyway to make the RichTextBox stop jumping to the top after a drag-drop from it?
1
8534
by: John Devlon | last post by:
Hi I would like to create a file upload system, using file drag and drop functionality. Does anyone know how ? John
1
2912
by: Steve Bottoms | last post by:
Hi, all! Using VB .Net 2k5 under Vista Business... I'm trying to put together a very basic drag-and-drop for file copying, and can't seem to get DragDrop events (Form, PictureBox, TextBox, etc) to fire at all, and DragEnter only fires if the drag operation STARTS on the form (kinda defeating the purpose of a drag-and-drop file copier). Is there some trick to getting it to work? I've tried several different samples from MSDN and this...
16
11866
by: John | last post by:
I am looking for VBA code that will work with Access 2003 to enable dragging and dropping a file/folder name from Windows XP Explorer into an Access form's text box. This is a common functionality that most Windows programs have, so I'm suprised it's not easier to implement in Access/VBA. Through Google, I found two VB6 examples and one VBA example on the Access Web written by Dev Ashish. The VB6 examples used loops to keep checking...
0
1309
by: babai28 | last post by:
Hi, I have a situation where in a winform application I have a tree view from which I need to drag drop tree nodes into a textBox contained in another application window. I used the following code to handle the drag dragEnter and the dragDrop event of the textBox: private void txtTrue_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(TreeNode))) { //Create a New...
0
9870
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10942
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10610
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10310
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7855
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7035
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5696
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3142
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.