473,889 Members | 1,444 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 9735
blurryanthem
43 New Member
I have added the code to my program , but it only seems to resolve the copying to the root drive ( ex. f:)

But not when another folder is created within that drive ( ex. f:\new ) - the same error is thrown.
Feb 10 '11 #61
blurryanthem
43 New Member
Also I have trouble on the copy process, wherein If i need to just "replace all" and not anymore mind the individual checking of existing file.

Like I am thinking that after checking if a file exist there should be options to:

1. Replace All
a. If yes, then it should proceed to start copy and overwrite all existing files
b. If no, then maybe prompt the options to:
* Replace only this file?
* Skip this file?
* Cancel

Does this makes sense?
Feb 10 '11 #62
blurryanthem
43 New Member
Sir Geur,

Can you help me on these options instead?

Expand|Select|Wrap|Line Numbers
  1. If Dir(SaveTo.Text & "\" & FILETO) <> "" Then
  2.                 MESSAGE = MsgBox("The file " & FILETO & " already exist!." & vbNewLine & _
  3.                      "Replace existing files?" & vbNewLine & _
  4.                     vbNewLine & _
  5.                      "Yes to All. [Yes]" & vbNewLine & _
  6.                      "This file only. [No]" & vbNewLine & _
  7.                     "Cancel copy process. [Cancel]", vbYesNoCancel)
  8.                 FILEEXIST = True
  9.                 End If
  10.  
Or any way where I could have options like:
- yes to all
- this file only
- skip this file
- cancel copy

any help?

Thanks!
Feb 11 '11 #63
Guido Geurs
767 Recognized Expert Contributor
The code=
Expand|Select|Wrap|Line Numbers
  1. ... 
  2. If Dir$(SaveTo.Text, vbVolume) = "" Then
  3. ...
checks if a volumename exist for the drive!
If it's an USB stick without a name then the code exit the sub.
I have changed the check with a FileSystemObjec t because you can't check it with Dir$ ( !! add the reference : "Microsoft Scripting Runtime" to the project if you want to use a FSO).
The standard msgbox can't be adapted.
For a custom Msgbox: you have to create your own! (see attachment)
Feb 12 '11 #64
blurryanthem
43 New Member
Sir Geur,

I just tried the code and it worked only when saving files into the root of a flash drive/memory device.
However, if the root drive is empty and you try to create a folder to that flash drive for saving it throws out an error instead. But if the root drive of a flash drive has something ..then creation of a folder and saving of files innto that folder is okay.

I also ran into another problem in my whole copy process ;( It really worries me alot now... my copy process seems to not work properly already after I tried the cases.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim fselectIDX As Integer
  3. Dim LOGTEXT As String
  4.  
  5. Private Sub ComSaveLog_Click()
  6. Dim MESSAGE As Variant
  7. Dim OUTPUTFN As Integer
  8.    If Dir(SaveTo.Text & "\Log.txt") <> "" Then _
  9.       MESSAGE = MsgBox("The file Log.txt exist !" & vbNewLine & "Overwrite ?", vbOKCancel)
  10.    If MESSAGE = vbCancel Then Exit Sub
  11.    OUTPUTFN = FreeFile
  12.    On Error GoTo ErrWriting
  13.    Open SaveTo.Text & "\Log.txt" For Output As #OUTPUTFN
  14.       Print #OUTPUTFN, LOGTEXT
  15.    Close #OUTPUTFN
  16. Exit Sub
  17. ErrWriting:
  18.    Close #OUTPUTFN
  19.    MsgBox ("There is an error writing the settings file !")
  20. End Sub
  21.  
  22. Private Sub ComShowLog_Click()
  23. Dim NOTEPADSHELL As Double
  24.    NOTEPADSHELL = Shell("Notepad " & SaveTo.Text & "\Log.txt", vbNormalFocus)
  25. End Sub
  26.  
  27. '§ Loads Form
  28. Private Sub Form_Load()
  29.     Picture1.OLEDropMode = 1      '§ manual
  30.     Text1(0).Top = -Text1(0).Height + 180
  31.     CopyTimes(0).Top = -CopyTimes(0).Height + 180
  32.  
  33.     With VScrollFiles
  34.       .Visible = False
  35.       .Min = -30
  36.    End With
  37.    ShapeProgress.Width = 0
  38. End Sub
  39.  
  40. '§ Opens Windows Explorer
  41. Private Sub OpenWEBtn_Click()
  42.     Dim Det As Long
  43.     Det = Shell("explorer.exe /e, C:\", vbNormalFocus)
  44. End Sub
  45.  
  46. '§ Selects Drive
  47. Private Sub Drive1_Change()
  48. Dir1.Path = Drive1.Drive
  49. End Sub
  50.  
  51. '§ Selects Directory within selected Drive
  52. Private Sub Dir1_Change()
  53. SaveTo.Text = Dir1.Path
  54. End Sub
  55.  
  56. '§ Compares FrameFix vs FrameSlide height
  57. Private Function Calc_FrameSlide_Height()
  58.    FrameSlide.Height = Text1.Count * Text1(0).Height
  59.    If FrameSlide.Height > FrameFix.Height Then
  60.       With VScrollFiles
  61.          .Max = (FrameSlide.Height - FrameFix.Height) / 10
  62.          .SmallChange = 200
  63.          .LargeChange = FrameFix.Height / 10
  64.          .Visible = True
  65.       End With
  66.    Else
  67.       VScrollFiles.Visible = False
  68.    End If
  69. End Function
  70.  
  71. '§ Handles the vertical scroll bar
  72. Private Sub VScrollFiles_Change()
  73. FrameSlide.Top = -VScrollFiles.Value * 10
  74. End Sub
  75.  
  76. '§ Handles the dragged dropped files and loads them into the Text1 texbox array
  77. Private Sub Picture1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  78. Dim i As Integer
  79. Dim dCount As Integer
  80.  
  81.       On Error GoTo No_File_info
  82.       i = Text1.Count - 1
  83.  
  84.       For dCount = 1 To Data.Files.Count
  85.          Load Text1(i + dCount)
  86.          With Text1(i + dCount)
  87.             .Top = Text1(i + dCount - 1).Top + Text1(0).Height
  88.             .Text = (Data.Files.Item(dCount))
  89.             .Visible = True
  90.          End With
  91.  
  92.          Load CopyTimes(i + dCount)
  93.          With CopyTimes(i + dCount)
  94.             .Top = CopyTimes(i + dCount - 1).Top + CopyTimes(0).Height
  95.             .Text = 1
  96.             .Visible = True
  97.          End With
  98.  
  99.       Next
  100.       FrameSlide.Height = Text1.Count * Text1(0).Height
  101.       If FrameSlide.Height > FrameFix.Height Then
  102.          With VScrollFiles
  103.             .Max = (FrameSlide.Height - FrameFix.Height) / 10
  104.             .SmallChange = 200
  105.             .LargeChange = FrameFix.Height / 10
  106.             .Visible = True
  107.          End With
  108.       Else
  109.          VScrollFiles.Visible = False
  110.       End If
  111. Exit Sub
  112. No_File_info:
  113.    MsgBox "No File name from Explorer"
  114. End Sub
  115.  
  116. '§ Specifies a numeric entry only in the CopyTimes textbox
  117. Private Sub CopyTimes_KeyPress(Index As Integer, KeyAscii As Integer)
  118. If Not (KeyAscii = vbKeyBack) Then
  119.     If Not Chr(KeyAscii) Like "#" Then
  120.     KeyAscii = 0
  121.     MsgBox ("Number entry only.")
  122.     End If
  123. End If
  124. End Sub
  125.  
  126. '§ Deletes individual selected file
  127. Private Sub Text1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  128.    fselectIDX = Index
  129.    If Button = vbKeyLButton Then PopupMenu PUMenu_Files
  130. End Sub
  131.  
  132. '§ Deletes individual selected file
  133. Private Sub PUMenu_DeleteFile_Click()
  134. Dim BOXidx As Integer
  135.    If fselectIDX <> Text1.Count Then '§ if not last box
  136.       For BOXidx = fselectIDX To Text1.Count - 2
  137.          Text1(BOXidx).Text = Text1(BOXidx + 1).Text
  138.          CopyTimes(BOXidx).Text = CopyTimes(BOXidx + 1).Text
  139.       Next
  140.       Unload Text1(Text1.Count - 1)
  141.       Unload CopyTimes(CopyTimes.Count - 1)
  142.    Else '§ if last box
  143.       Unload Text1(fselectIDX)
  144.       Unload CopyTimes(fselectIDX)
  145.    End If
  146.    Call Calc_FrameSlide_Height
  147. End Sub
  148.  
  149. '§ Handles the whole COPY/REPLICATION process
  150. Private Sub ReplicateBtn_Click()
  151. Dim FSO As FileSystemObject
  152. Dim DRIVEEXIST As Boolean
  153. Dim NEWPATH As String
  154.  
  155. '§ Check Folder from SaveTo
  156. Dim ARRFOLDERS() As String
  157. Dim ARRFOLDERSidx As Integer
  158. Dim ARRFOLDERScount As Integer
  159. Dim PATHpart As String
  160.  
  161. '§ count number of copies
  162. Dim COPIESidx As Integer
  163. Dim COPYPROGRESS As Integer
  164. Dim COPYTOTAL As Integer
  165.  
  166. '§ Loop through files to copy
  167. Dim FILENAME As String
  168. Dim NAME As String
  169. Dim EXTENTION As String
  170. Dim FILETO As String
  171. Dim STARTFILEidx As Integer
  172. Dim FILEidx As Integer
  173. Dim LOGTEXT As String
  174. Dim FILEEXIST As Boolean
  175.  
  176. '§ Loop through files to print
  177. Dim hFile As Long
  178. Dim sFilename As String
  179.  
  180.  
  181. '§ General
  182. Dim MESSAGE As Variant
  183. Dim MSGFORM As New Form_MSG_FileExist
  184. Dim MSGWHATTODO As String
  185.     Set FSO = CreateObject("scripting.filesystemobject")
  186.  
  187. '§ check if Files to copy <> 0
  188.    If Text1.Count = 1 Then '§ only the original textbox with index=0
  189.       MsgBox "There are no files to copy !" & vbNewLine & _
  190.                "Please, drop files into the Dropzone !"
  191.       Exit Sub
  192.    End If
  193.  
  194. '§ Check destination drive from SaveTo
  195. If SaveTo.Text = "" Then
  196.       MsgBox ("Please specify a copy destination.")
  197.       Exit Sub
  198. End If
  199.  
  200. '§ check if drive exist
  201.    DRIVEEXIST = FSO.DriveExists(SaveTo.Text)
  202.    If Not DRIVEEXIST And Len(SaveTo.Text) = 3 Then
  203.       MsgBox "There is no Drive with this name !"
  204.       Exit Sub
  205.    End If
  206.  
  207. '§ If drive don't exist: exit
  208.    If Dir$(SaveTo.Text, vbVolume) = "" Then
  209.       MsgBox "The drive don't exist !"
  210.       Exit Sub
  211.    End If
  212.  
  213. '§ path= root: copy
  214.    If Len(SaveTo.Text) = 3 Then GoTo Start_Copy
  215.  
  216. '§ Check Folder from SaveTo: create new path?
  217.    If Dir$(SaveTo.Text, vbDirectory) = "" Then
  218.       MESSAGE = MsgBox("The folder " & SaveTo.Text & " doesn't exist." & _
  219.                      vbNewLine & "Create the folder ?", vbYesNo)
  220.       If MESSAGE = vbYes Then
  221.          ARRFOLDERS = Split(SaveTo.Text, "\") '§ set folders in array
  222.          For ARRFOLDERSidx = LBound(ARRFOLDERS) To UBound(ARRFOLDERS) '§ loop to folders
  223.             PATHpart = ""
  224.             For ARRFOLDERScount = LBound(ARRFOLDERS) To ARRFOLDERSidx '§ build path
  225.                PATHpart = PATHpart & ARRFOLDERS(ARRFOLDERScount) & "\"
  226.             Next
  227.             If Dir$(PATHpart, vbDirectory) = "" Then MkDir (PATHpart) '§ create folders
  228.          Next
  229.       Else
  230.          Exit Sub
  231.       End If
  232.    End If
  233.  
  234. Start_Copy:
  235. '§ count number of copies
  236.    COPYTOTAL = 0
  237.    For COPIESidx = 1 To Text1.Count - 1
  238.       COPYTOTAL = COPYTOTAL + Val(CopyTimes(COPIESidx))
  239.    Next
  240.  
  241. '§ Loop through files to copy
  242.    COPYPROGRESS = 0
  243.    LabelProgress.Caption = "Copying"
  244.    LOGTEXT = ""
  245.  
  246. For STARTFILEidx = 1 To Text1.Count - 1
  247.       '§ find FILENAME (NAME + EXTENTION)
  248.       FILENAME = Mid(Text1(STARTFILEidx), InStrRev(Text1(STARTFILEidx), "\") + 1)
  249.       '§ find NAME
  250.       NAME = Left(FILENAME, InStrRev(FILENAME, ".") - 1)
  251.       '§ find EXTENTION
  252.       EXTENTION = Mid(FILENAME, InStrRev(FILENAME, ".") + 1)
  253.          '§ Make copies
  254.          For FILEidx = 1 To Val(CopyTimes(STARTFILEidx).Text)
  255.          FILETO = NAME & "(" & FILEidx & ")" & "." & EXTENTION
  256.          FILEEXIST = False
  257.          If Dir(SaveTo.Text & "\" & FILETO, vbArchive) <> "" And _
  258.                MSGWHATTODO <> "Yes to All" Then
  259.             MSGWHATTODO = MSGFORM.ShowDialog(FILETO, Me)
  260.          Else
  261.             GoTo Copy_File
  262.          End If
  263.          Me.Refresh
  264.          Select Case MSGWHATTODO
  265.          Case "File Only"
  266.             GoTo Copy_File
  267.          Case "Skip this file"
  268.             GoTo NextFile
  269.          Case "Cancel"
  270.             Exit Sub
  271.          End Select
  272.  
  273. Copy_File:
  274.          FileCopy Text1(STARTFILEidx), SaveTo.Text & "\" & FILETO
  275.          DoEvents
  276.          '§ add filename for printing log
  277.          If FILEEXIST Then
  278.             LOGTEXT = LOGTEXT & FILETO & ": Replaced" & vbNewLine
  279.          Else
  280.             LOGTEXT = LOGTEXT & FILETO & ": New" & vbNewLine
  281.          End If
  282. NextFile:
  283.          COPYPROGRESS = COPYPROGRESS + 1
  284.          LabelProgress.Caption = "Progress : " & COPYPROGRESS & "/" & _
  285.                               COPYTOTAL & " copied"
  286.          ShapeProgress.Width = (COPYPROGRESS / COPYTOTAL) * ShapeProgressBack.Width
  287.       Next
  288.  
  289. FileError:
  290.             Select Case Err.Number
  291.             Case 61
  292.             MsgBox ("Destination drive is full.")
  293.             Case 70
  294.             MsgBox ("Permission Denied. The Memory Device is write protected.")
  295.             End Select
  296.    Next
  297.    LabelProgress.Caption = "Done"
  298.    ShapeProgress.Width = 0
  299.  
  300. End Sub
  301.  
  302. '§ Deletes all files in the list
  303. Private Sub ClearBtn_Click()
  304. Dim i As Integer
  305.  
  306.     If Text1.Count = 1 Then
  307.         MsgBox ("There are no files to delete.")
  308.     Else
  309.         For i = 1 To Text1.UBound
  310.             Unload Text1(i)
  311.             Unload CopyTimes(i)
  312.         Next
  313.         Call Calc_FrameSlide_Height
  314.      End If
  315. End Sub
  316.  
  317. '§ Opens Saved Log file
  318. Private Sub LogBtn_Click()
  319.     Dim LogFile As String
  320.     Dim NOTEPADSHELL As Double
  321.  
  322.     If Text1.Count = 1 Then
  323.        MsgBox "There are no copied files." & vbNewLine & _
  324.                 "Log not created."
  325.     Else
  326.     LogFile = "notepad c:\Log.txt"
  327.     Shell LogFile
  328.     'NOTEPADSHELL = Shell("Notepad " & SaveTo.Text & "\Log.txt", vbNormalFocus)
  329.     End If
  330. End Sub
  331.  
  332.  
  333.  
Attached Files
File Type: zip Final.zip (1.89 MB, 118 views)
Feb 15 '11 #65

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

Similar topics

1
1919
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
4344
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
1679
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
10174
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
1787
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
8536
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
2917
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
11875
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
9961
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
10785
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...
1
10887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
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
9603
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...
0
5825
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...
0
6025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4644
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4249
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.