473,889 Members | 1,409 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 9734
Guido Geurs
767 Recognized Expert Contributor
Yes, TextFiles(xx) is the textbox in the list and xx is the index of the textboxes in the frame.

the code for ReplicateBtn_cl ick() will be something like:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ReplicateBtn_click()
  2. Dim FILENAME as string
  3. Dim NAME as string
  4. Dim EXTENTION as string
  5. Dim FILETO as string
  6. Dim STARTFILEidx as integer
  7. Dim FILEidx as integer
  8. Dim LOGTEXT as string
  9.   '§ Loop trough files to copy
  10.   for STARTFILEidx  = 1 to textfiles.count -1
  11.     '§ find FILENAME (NAME + EXTENTION)
  12.     FILENAME = Mid(TextFiles(STARTFILEidx ),Instrrev(TextFiles(STARTFILEidx ),"\")+1)
  13.     '§ find NAME
  14.     NAME = Left(FILENAME,Instrrev(FILENAME,".")-1) 
  15.     '§ find EXTENTION
  16.     EXTENTION = Mid(FILENAME,Instrrev(FILENAME,".")+1)
  17.       '§ Make copies
  18.       for FILEidx =1 to val(textCopies(STARTFILEidx).text)
  19.         FILETO = NAME & "(" & FILEidx & ")" & EXTENTION  
  20.         FileCopy textfiles(STARTFILEidx), TextToPath.text & "\" & FILETO
  21.         '§ add filename for printing log
  22.         LOGTEXT= LOGTEXT & FILETO & Vbnewline
  23.       next
  24.   next
  25.   '§ print Log
  26.   ...
  27.   ...
  28. End Sub
PS: this code is not tested !!! I have just typed it in de mail !!!!
Jan 5 '11 #31
blurryanthem
43 New Member
Thanks for the confirmation Sir Geurs.
So val(textCopies. text) means any value that I enter to my CopyTimes.text, right?

I will try this code in a little while and tell you if it works.
Jan 5 '11 #32
Guido Geurs
767 Recognized Expert Contributor
It's recommended to add errortraps in the code!
Check if the file already exist in the folder before copying it with something like:

Expand|Select|Wrap|Line Numbers
  1. Dim FILENAME As String
  2. Dim NAME As String
  3. Dim EXTENTION As String
  4. Dim FILETO As String
  5. Dim STARTFILEidx As Integer
  6. Dim FILEidx As Integer
  7. Dim LOGTEXT As String
  8.    '§ Loop trough files to copy
  9.    For STARTFILEidx = 1 To TextFiles.Count - 1
  10.       '§ find FILENAME (NAME + EXTENTION)
  11.       FILENAME = Mid(TextFiles(STARTFILEidx), InStrRev(TextFiles(STARTFILEidx), "\") + 1)
  12.       '§ find NAME
  13.       NAME = Left(FILENAME, InStrRev(FILENAME, ".") - 1)
  14.       '§ find EXTENTION
  15.       EXTENTION = Mid(FILENAME, InStrRev(FILENAME, ".") + 1)
  16.          '§ Make copies
  17.          For FILEidx = 1 To Val(TextTimes(STARTFILEidx).Text)
  18.             FILETO = NAME & "(" & FILEidx & ")" & EXTENTION
  19.             If Dir$(TextToPath.Text & "\" & FILETO) <> "" Then
  20.                MsgBox ("The file " & FILETO & " exist !")
  21.                Exit Sub
  22.             End If
  23.             FileCopy TextFiles(STARTFILEidx), TextToPath.Text & "\" & FILETO
  24.             '§ add filename for printing log
  25.             LOGTEXT = LOGTEXT & FILETO & vbNewLine
  26.          Next
  27.    Next
  28.    '§ print Log
  29.  
  30.  
PS:
Val(TextTimes(S TARTFILEidx).Te xt) is the number of copies
Jan 5 '11 #33
blurryanthem
43 New Member
Sir Geur,

I just tried your code above and yes it does work with a little error wherein the files copied were saved as:

ABT GTI 00(1)jpg
ABT GTI 00(2)jpg
ABT GTI 00(3)jpg
CertificatePdfS ervlet_eantipal (1)pdf
CertificatePdfS ervlet_eantipal (2)pdf
CertificatePdfS ervlet_eantipal (3)pdf

Instead of :

ABT GTI 00(1).jpg
ABT GTI 00(2).jpg
ABT GTI 00(3).jpg
CertificatePdfS ervlet_eantipal (1).pdf
CertificatePdfS ervlet_eantipal (2).pdf
CertificatePdfS ervlet_eantipal (3).pdf

I just added a "." to how the FILETO is being written from your code:
FILETO = NAME & "(" & FILEidx & ")" & EXTENTION

To:
FILETO = NAME & "(" & FILEidx & ")" & "." & EXTENTION

Thanks alot Sir Geur. I've learned so much.
I'll work on the Log List and other file error trapping like:

a. copytimes no value
b. saveto folder already exist/does not exist
c. fileto already exist at saveto ( already at your code)
d. no dragged files - nothing to replicate

Query:
1. Is it practical to autoclear the list( textfiles) after a successful copy? Just to prepare again the for a new list
OR just create a clear button to clear the list?
2. Is it practical to set the SaveTo textbox to Locked? Just to prevent the user from editing a non-existent directory..
OR shall I keep it unlocked to give user freedom to create a new folder or manually change a directory?

The way I locked CopyTimes textbox for numeric entry only.
Jan 5 '11 #34
Guido Geurs
767 Recognized Expert Contributor
Yes You are right, I'm sorry for the error in the code.

Q1: I think an auto clear is not practical because, if there is an error while copying, all the work for building the list will be lost.

Q2: I think it's more practical to let the textbox editable for the user.
He can go to the path of an existing folder and change just a letter to create a new one.
The code must be adapted to it with=>
Before copying:
- check if the folder exist
- if not, ask the user if it must be created.

Q3 code for CopyTimes (max 5 digits: tested in = If Len(.Text) < 5 Then ...)
Expand|Select|Wrap|Line Numbers
  1. Private Sub TextTimes_KeyUp(Index As Integer, KeyCode As Integer, Shift As Integer)
  2.    With TextTimes(Index)
  3.       Select Case KeyCode
  4.       Case 48 To 57 '§ numbers
  5.          If Len(.Text) < 5 Then .Text = .Text & Chr(KeyCode)
  6.       Case 8 '§ back
  7.          If Len(.Text) > 0 Then _
  8.             .Text = Left(.Text, Len(.Text) - 1)
  9.       Case 46 '§ delete
  10.          .Text = ""
  11.       End Select
  12.    End With
  13. End Sub
Jan 5 '11 #35
blurryanthem
43 New Member
Sir Geur,

I am trying to enable the SaveTo to create a new directory in case a new folder will be created by user for new destination aside from the given directories. I'm just not sure what's wrong with my code here.. SaveTo.text gets the new directory value..but an error is being thrown out...It was not able to create a new directory :(

Expand|Select|Wrap|Line Numbers
  1. Private Sub SaveTo_Click()
  2. Dim newDir As String
  3.  
  4. newDir = SaveTo.Text & "\"
  5. On Error Resume Next
  6. MkDir (newDir)
  7.  
  8. End Sub
  9.  
It throws a run time error '76' Path not found.
Please help.
Jan 5 '11 #36
blurryanthem
43 New Member
I have to agree with your answer in my Q1. Anyways I just provided a new clear list button to answer that.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ClearBtn_Click()
  2. Dim i As Integer
  3.         For i = 1 To Text1.UBound
  4.              Unload Text1(i)
  5.              Unload CopyTimes(i)
  6.         Next
  7.         Call Calc_FrameSlide_Height
  8. End Sub
  9.  
As for Q3 here is my previous code. This does not limit to any input length though which is a bit clumsy but locks any invalid keypresses. You think this is practical?
Expand|Select|Wrap|Line Numbers
  1. Private Sub CopyTimes_KeyPress(Index As Integer, KeyAscii As Integer)
  2. If Not (KeyAscii = vbKeyBack) Then
  3.     If Not Chr(KeyAscii) Like "#" Then
  4.     KeyAscii = 0
  5.     MsgBox ("Number entry only.")
  6.     End If
  7. End If
  8. End Sub
  9.  
I'll try your new code for the CopyTimes.
Jan 5 '11 #37
Guido Geurs
767 Recognized Expert Contributor
You can't make folders with MkDir if there is more than one folder missing.
You can only create the last folder and the previous must exist!
Like starting from : C:\test1\test2
You want : C:\test1\test2\ test3\test4
Or change a letter in the path : C:\test0\test2 (this is the same as creating 2 folders).

You have to build the path until the last folder.

The code to do that in the Duplicate command is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ComDuplicate_Click()
  2. '§ Check Folder from TextSaveTo
  3. Dim ARRFOLDERS() As String
  4. Dim ARRFOLDERSidx As Integer
  5. Dim ARRFOLDERScount As Integer
  6. Dim PATHpart As String
  7. Dim MESSAGE As Variant
  8. '§ Loop trough files to copy
  9. Dim FILENAME As String
  10. Dim NAME As String
  11. Dim EXTENTION As String
  12. Dim FILETO As String
  13. Dim STARTFILEidx As Integer
  14. Dim FILEidx As Integer
  15. Dim LOGTEXT As String
  16. '§ Check Folder from TextSaveTo
  17.    If Dir$(PATHpart, vbDirectory) <> "" Then
  18.       MESSAGE = MsgBox("The folder = " & TextSaveTo.Text & " don't exist !" & _
  19.                      vbNewLine & "Create the folder ?", vbYesNo)
  20.       If MESSAGE = vbYes Then
  21.          ARRFOLDERS = Split(TextSaveTo.Text, "\") '§ set folders in array
  22.          For ARRFOLDERSidx = LBound(ARRFOLDERS) To UBound(ARRFOLDERS) '§ loop to folders
  23.             PATHpart = ""
  24.             For ARRFOLDERScount = LBound(ARRFOLDERS) To ARRFOLDERSidx '§ build path
  25.                PATHpart = PATHpart & ARRFOLDERS(ARRFOLDERScount) & "\"
  26.             Next
  27.             If Dir$(PATHpart, vbDirectory) = "" Then MkDir (PATHpart) '§ create folders
  28.          Next
  29.       Else
  30.          Exit Sub
  31.       End If
  32.    End If
  33. '§ Loop trough files to copy
  34.    For STARTFILEidx = 1 To TextFiles.Count - 1
  35.       '§ find FILENA...
  36. ....
  37. ....
Jan 6 '11 #38
Guido Geurs
767 Recognized Expert Contributor
Q3 It's a nice code.
If it's working in Your program, it's OK.
Only 'Delete' is not working => If You want erase all, You have to place the cursor before the numbers for the key 'Delete' or after the numbers if You want use the 'Back'.

You can eliminate the restriction of 5 digits by changing the code=
Expand|Select|Wrap|Line Numbers
  1.       Case 48 To 57 '§ numbers
  2.          If Len(.Text) < 5 Then .Text = .Text & Chr(KeyCode)
  3.       Case 8 '§ back
by
Expand|Select|Wrap|Line Numbers
  1.       Case 48 To 57 '§ numbers
  2.          .Text = .Text & Chr(KeyCode)
  3.       Case 8 '§ back
Jan 6 '11 #39
blurryanthem
43 New Member
Sir Geur,

As with the creation of a new folder, is the ComDuplicate_Cl ick() , a new button that should be added on my form?

As you can see I have the drivelist box with
Expand|Select|Wrap|Line Numbers
  1. Private Sub Drive1_Change()
  2. Dir1.Path = Drive1.Drive
  3. End Sub
  4.  
Which will populate to the DirListBox
Expand|Select|Wrap|Line Numbers
  1. Private Sub Dir1_Click()
  2. SaveTo.Text = Dir1.Path
  3. End Sub
  4.  
Now I want this textbox ( SaveTo) to catch the Dir1.Path plus with an editable textbox that will enable the user to add/create new folder name to the SaveTo textbox.

I'm a bit confused with the new duplicate command button.?
Jan 6 '11 #40

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
10173
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
11187
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
10784
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
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
9602
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
7148
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
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...
1
4642
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
3
3252
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.