473,394 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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 #1

✓ answered by Guido Geurs

I think there are 2 types of deletion:
The PUmenu delete is only used for deletion of a file the user don't want replicate (has been dropped by mistake)
A button with delete for clearing the boxes with the code=
Expand|Select|Wrap|Line Numbers
  1. For i=1 to textfiles.count
  2.   unload textfiles(i)
  3.   unload texttimes(i)
  4. next
This way You don't need the checkboxes !

64 9582
Guido Geurs
767 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4.    Text1.OLEDropMode = 1      '§ manual
  5. End Sub
  6.  
  7. Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  8. Dim DATACOUNTER As Integer
  9.    With Text1
  10.       On Error GoTo No_File_info
  11.       For DATACOUNTER = 1 To Data.Files.Count
  12.          .Text = .Text & Data.Files.Item(DATACOUNTER) & vbNewLine
  13.       Next
  14.    End With
  15. Exit Sub
  16. No_File_info:
  17.    MsgBox "No File name from Explorer"
  18. End Sub
  19.  
Dec 22 '10 #2
Hello Sir Geur,

Thanks for the code. But It seemed like it was only able to copy all the selected files in one textbox. It did not even create a new line if that is the purpose of vbNewLine?

The requirement is to be able to drag multiple files ( ex. 3 files ) into my vbform and drop those files in 3 textboxes at runtime displaying their filenames. I do not limit the dragging to 3files only but even more. Is that possible sir?

Thanks!
Dec 22 '10 #3
It only showed the varchar sign to separate the selected files. I would want to display each selected dragged file into different textboxes.
Dec 22 '10 #4
Guido Geurs
767 Expert 512MB
It's for VB6 , no ??

If You want more than one line in a textbox set the property "Multiline" to TRUE (see attached GIF)

Do You want multy Textboxes DEPENDING on the number of selected filenames (see attachment "Textboxes.GIF) ?

Or are there a max of textboxes on the form (like 10 or so)
Attached Images
File Type: gif Multiline.gif (923 Bytes, 318 views)
File Type: jpg Textboxes.jpg (39.1 KB, 494 views)
Dec 22 '10 #5
Sir Geur,

I am actually making a file replicator tool as a simple project that will enable a user to locate a file to copy ( in my cases from explorer ) and then replicate it a number of times. That's why I need to display each copied files in different textboxes so that user is given an option to specify how many times each different image is to be replicated. And yes..I would need Textboxes.jpg format.

Thanks sir.
Dec 22 '10 #6
Sorry..but yes It's VB6. I was thinking of unlimitted file selection so I am expecting for a number of textboxes too. Just to give the user big option in the file selection and file replication.
Dec 22 '10 #7
Guido Geurs
767 Expert 512MB
Attached is a code.
Just drop a bunch of files in the Image and the textboxes will be created with the filename in it.
Attached Files
File Type: zip drag drop files into a textbox from winexplorer_v1.zip (2.6 KB, 486 views)
Dec 22 '10 #8
I have tried the code and it seemed like it's limitation is during the file selection. Yes it allows the user to for multiple file selection from the same directory only at one time then drag it to the image. But it would be a problem if some files to be selected are located in another directory. Doing the 2nd thing proceeds to the Error trapping which is confusing :(

Or do you have any better idea on how to allow the user to do single/multiple file selection then drag the chosen files at the same time or not , then populate those filenames in different textboxes? That is the only way that I can think of now.

The desired tool looks like this ..sorry I just got back in the coding thing.

Dec 22 '10 #9
Guido Geurs
767 Expert 512MB
The sample is just explaining how to multiply textboxes according to the number of files.
The code is not complete to redo it or add other files !!!(the textboxes must be cleared)

Sorry but it's still not clear to me what You want to do with the files.
What I under stand (?) for now is that You want to centralize different files from different folder in textboxes.
WHY textboxes and not a listbox?
What do You want to do with these filenames?

Do You have already some code?
Please attach it in Bytes if possible.
Dec 22 '10 #10
Hello Sir Geur,
Sorry if that confused you.

I'm trying to create a file replicator tool which will enable the user to copy/replicate certain files a no. of times and save it into a directory/drive.

On the tool:
FileSearch Button -> Opens the windows explorer ( for file selection )


Textbox1
-> where filename of selected file is displayed ( wherein selection from explorer should be via drag and drop for ease of use )
-> should only appear when a file is drag/drop in the FilestoCopy Frame
-> may add more textboxes at run time depending on how many files were selected

During a drag/drop
-> another textbox ( or any container/editor) should be created at the right side of the textbox for the filename show, purpose of the textbox at the right is it is where user will manually input no. of times that specific file is to be copied/replicated in a certain drive.

I just can't find how to do that. I have only these ones for now.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     Dim Det As Long
  3.     Det = Shell("explorer.exe /e, C:\", vbNormalFocus)
  4.  
  5. End Sub
  6.  
  7. Private Sub Command3_Click()
  8. TextBox.Text = ""
  9. End Sub
  10.  
  11. Private Sub Form_Load()
  12.     TextBox.OLEDropMode = 1      '§ manual
  13. End Sub
  14.  
  15. Private Sub TextBox_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  16.  
  17. Dim i As Integer
  18.     Load Text1(DATACOUNTER)
  19.     With TextBox
  20.        For i = 1 To Data.Files.Count
  21.           .Text = .Text & Data.Files.Item(i) & vbNewLine
  22.        Next
  23.     End With
  24.  End Sub
  25.  
Dec 22 '10 #11
If there is a better way of doing it, I hope you could help. Thanks in advance.
Dec 22 '10 #12
Guido Geurs
767 Expert 512MB
If I'm right, it looks like in the attached GIF ?
Attached Images
File Type: jpg Plan.jpg (45.4 KB, 510 views)
Dec 22 '10 #13
More or less like this too:



Here's the modified code though.


Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Sub ClearAllBtn_Click()
  4. Text1.Text = ""
  5. End Sub
  6.  
  7. Private Sub OpenWEBtn_Click()
  8.     Dim Det As Long
  9.     Det = Shell("explorer.exe /e, C:\", vbNormalFocus)
  10. End Sub
  11.  
  12. Private Sub Form_Load()
  13.     DropArea.OLEDropMode = 1      '§ manual
  14. End Sub
  15.  
  16. Private Sub DropArea_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  17. Dim i As Integer
  18. On Error GoTo No_File_info
  19. For i = 1 To Data.Files.Count
  20. Load Text1(i)
  21.         With Text1(i)
  22.             .Top = Text1(0).Top + i * (Text1(0).Height + 15)
  23.             .Text = Data.Files.Item(i)
  24.             .Visible = True
  25.         End With
  26.       Next
  27.     Exit Sub
  28. No_File_info:
  29.    MsgBox "No File name from Explorer"
  30. End Sub
  31.  
  32.  
To Dos yet:
a. I'm still having trouble with ClearList button
b. Has not coded for Replicate Button yet
c. Has not figured out how to create again new textboxes to contain the no. of copy numbers

Thanks!
Dec 22 '10 #14
Guido Geurs
767 Expert 512MB
Questions=
Q1 All the selected files must be replicated with the same number (one textbox for the number)?
Or the user enters a number for each file (each file has a textbox with his number of replacations)?
Q2 the number of files for each replacation is not higher than +- 20 because there is no place in the form if more.
If it's more, we have to use a listbox or gridbox (depends on the answer on Q1)
Or a scrolling picturebox (max +_ 40 files).
Dec 22 '10 #15
Answers:
Q1 All the selected files must be replicated with the same number (one textbox for the number)?
Or the user enters a number for each file (each file has a textbox with his number of replacations)?
- The user enters a number ( for no. of copy ) for each file ( may be the same, maybe not depending on the user )
- We could limit the digit entry to be max of 5 digits
Q2 the number of files for each replacation is not higher than +- 20 because there is no place in the form if more.
If it's more, we have to use a listbox or gridbox (depends on the answer on Q1)
- i would want the program to give no limit to the number of files to be selected , then dragged and dropped into the frame.. i'm not familiar how gridbox works.. but I'm a bit comfortable with textboxes
- is there a way to automatically extend/stretch the form below depending on the no of textboxes created?
- if Listbox.. how do I create a another container for the number entry ( no. of copy ) for each populated file in the list box?
Or a scrolling picturebox (max +_ 40 files).
Dec 22 '10 #16
as for picturebox...i believe it does not support all file types.. correct?
Dec 22 '10 #17
Guido Geurs
767 Expert 512MB
Attached an example how it can be done with textboxes
There is a limit with textboxes !!! = the top of the sliding frame !!!

I will see what i can do with a grid.
Dec 23 '10 #18
Guido Geurs
767 Expert 512MB
Attached are examples with:
v2.1 = with GRID : need an image to drop in the data.
v3.2 = with MSFlexGrid : no need for image to drop in: MSFlexGrid has his own "dragdrop" event.
Dec 24 '10 #19
Hello Mr Geur,
Sorry for the delayed response due to the Holidays. Happy Holidays by the way :)

I was not able to run drag drop files into a textbox from winexplorer_v2.1.zip , but I will try the other 2 with textboxes and grid.
Dec 30 '10 #20
Sir Geurs,

Thanks alot, I used "drag drop files into a textbox from winexplorer_v1.1.zip" as I prefer a textbox in my form. I loaded a checkbox as well using the same control array with the textboxes created at runtime.

The checkbox will be used later on to select final files for removal or replication ( in case the user mistakenly dragged/dropped a file ).

Can I use the same control array as my counter to be able to remove/replicate "checked" files? It will be easier to indicate them in checkboxes and provide only 1 REMOVE and REPLICATE button for the file manipulation.

Creation of textboxes and checkboxes at run time:
Expand|Select|Wrap|Line Numbers
  1. Private Sub DropArea_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  2. Dim i As Integer
  3. Dim dCount As Integer
  4.  
  5.       On Error GoTo No_File_info
  6.       i = Text1.Count - 1
  7.  
  8.       For dCount = 1 To Data.Files.Count
  9.  
  10.          Load Text1(i + dCount)
  11.          With Text1(i + dCount)
  12.             .Top = Text1(i + dCount - 1).Top + Text1(0).Height
  13.             .Text = Data.Files.Item(dCount)
  14.             .Visible = True
  15.          End With
  16.  
  17.          Load NumEntryBtn(i + dCount)
  18.          With NumEntryBtn(i + dCount)
  19.             .Top = NumEntryBtn(i + dCount - 1).Top + NumEntryBtn(0).Height
  20.             '.Text = i + dCount
  21.             .Visible = True
  22.          End With
  23.  
  24.         Load CheckBtn(i + dCount)
  25.         With CheckBtn(i + dCount)
  26.             .Top = CheckBtn(i + dCount - 1).Top + CheckBtn(i + dCount - 1).Height
  27.             .Visible = True
  28.         End With
  29.  
  30.       Next
  31.       FrameSlide.Height = Text1.Count * Text1(0).Height
  32.       If FrameSlide.Height > FrameFix.Height Then
  33.          With VScrollFiles
  34.             .Max = (FrameSlide.Height - FrameFix.Height) / 10
  35.             .SmallChange = 200
  36.             .LargeChange = FrameFix.Height / 10
  37.             .Visible = True
  38.          End With
  39.       Else
  40.          VScrollFiles.Visible = False
  41.       End If
  42. Exit Sub
  43. No_File_info:
  44.    MsgBox "No File name from Explorer"
  45. End Sub
  46.  

Unload Checkbx, Textbox corresponding to that checked checkbox in the array:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Clear_Click()
  2. Dim i As Integer
  3.  
  4.         For i = 1 To CheckBtn.Count
  5.             If CheckBtn(i).Value = vbChecked Then
  6.             Unload Text1(i)
  7.             Unload NumEntryBtn(i)
  8.             Unload CheckBtn(i)
  9.             End If
  10.         Next
  11.  
  12. End Sub
  13.  
Is this correct?
Dec 30 '10 #21
Sir Geurs,

You think this is better?



Thanks!
Dec 30 '10 #22
Guido Geurs
767 Expert 512MB
Looks OK but one question:
Why add a checkbox ? You can use a pop-up menu like in attachment v1.2.
One problem: if You delete a textbox, the index of the boxes will not be continues any more!! => how to program which indexes still exist and which not ???
There is also in the code the count used textboxes (= textbox.count) :o( to calculate the indexes for the next drop !
There is an other way: move the data one box up and delete the last textbox ?

I have also attached a new ZIP with the 2.1 version: it works on my PC (with XP Pro SP 3 and VB6 SP6)
Dec 30 '10 #23
Guido Geurs
767 Expert 512MB
attached v1.3 with delete and scroll-up of the data.
Use LMB on the textbox to delete (to pop-up the delete menu).
Dec 30 '10 #24
Sir Geur,

I think that a checkbox is for ease selection of which file to delete and replicate.

I have tried your v1.3 ( with delete and scroll-up of the data ) and deletion was not a problem. Although, I'm seeing that it would be a bit tedious for the user to manually click each of the files that needs to be deleted. While if we use checkbox, we will only hit one "remove/delete" button for all selected files ( w. checked checkboxes).

Do you agree?

Because the next thing that I would work here is the replicate to x times command.
Dec 30 '10 #25
Guido Geurs
767 Expert 512MB
I think there are 2 types of deletion:
The PUmenu delete is only used for deletion of a file the user don't want replicate (has been dropped by mistake)
A button with delete for clearing the boxes with the code=
Expand|Select|Wrap|Line Numbers
  1. For i=1 to textfiles.count
  2.   unload textfiles(i)
  3.   unload texttimes(i)
  4. next
This way You don't need the checkboxes !
Dec 31 '10 #26
Hello Sir Geur,

I've followed your suggestion about the pop up menus instead of checkboxes. This makes it alot easier now to select which files to delete if added mistakenly. This way the remaining files will be by default all the ones which should undergo the replication process.

I would like to ask though if there is a way in VB to save the selected files by by extracting the filenames from the full directory path? Then save it by listing.

Ex.
C:\dell\drivers\R182522\Help.txt ( ex. 5x to be copied)
C:\dell\drivers\R182522\test.dll ( ex. 3x to be copied)

Save this selected file to a specified directory with filename:

Help(1).txt
Help(2).txt
Help(3).txt
Help(4).txt
Help(5).txt
test(1).dll
test(2).dll
test(3).dll

I can't seem to extract the filename itself other than assigning a fix filename with index to all copied files..which is not helping. Any help Sir Geur?

Thanks
Jan 3 '11 #27
Guido Geurs
767 Expert 512MB
You can extract the filename from the path by cutting the string after the last "\" with:

Expand|Select|Wrap|Line Numbers
  1. FILENAME = Mid(TextFiles(xx),Instrrev(TextFiles(xx),"\")+1)
For adding an index: cut the FILENAME before and after the last "." like:

Expand|Select|Wrap|Line Numbers
  1. NAME = Left(FILENAME,Instrrev(FILENAME,".")-1)
  2. EXTENTION = Mid(FILENAME,Instrrev(FILENAME,".")+1)
Recombine the destination filename with index:

Expand|Select|Wrap|Line Numbers
  1. FILETO = NAME & "(" & index & ")" & EXTENTION
Jan 5 '11 #28
Sir Geur,

Does TextFiles(xx) stand for the textbox with the fullpath and file name in my prog? And does (xx) stand for it's array? All about this get filename is on one function right not part of the Replicatebtn_click() sub?

like in my code:

For i =1 To Text1.count
FILENAME = Mid(Text1(i),Instrrev(Text1(i),"\")+1)


In my ReplicateBtn_click() , can I use the FileCopy? like

FileCopy Text1.Text, SaveTo.Text

Is this correct?
Jan 5 '11 #29
I have actually asked the same thing for the replication process. I'm still really learning from this VB thing in which I am trying to enhance the old tool.

http://bytes.com/topic/visual-basic/...values-runtime
Jan 5 '11 #30
Guido Geurs
767 Expert 512MB
Yes, TextFiles(xx) is the textbox in the list and xx is the index of the textboxes in the frame.

the code for ReplicateBtn_click() 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
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 Expert 512MB
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(STARTFILEidx).Text) is the number of copies
Jan 5 '11 #33
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
CertificatePdfServlet_eantipal(1)pdf
CertificatePdfServlet_eantipal(2)pdf
CertificatePdfServlet_eantipal(3)pdf

Instead of :

ABT GTI 00(1).jpg
ABT GTI 00(2).jpg
ABT GTI 00(3).jpg
CertificatePdfServlet_eantipal(1).pdf
CertificatePdfServlet_eantipal(2).pdf
CertificatePdfServlet_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 Expert 512MB
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
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
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 Expert 512MB
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 Expert 512MB
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
Sir Geur,

As with the creation of a new folder, is the ComDuplicate_Click() , 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
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 Expert 512MB
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
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
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
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 Expert 512MB
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
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 Expert 512MB
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
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
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
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...
2
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...
1
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...
5
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...
0
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...
1
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
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)...
16
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...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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...

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.