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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • blurryanthem
    New Member
    • Dec 2010
    • 43

    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.
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    Code:
    Option Explicit
    
    Private Sub Form_Load()
       Text1.OLEDropMode = 1      '§ manual
    End Sub
    
    Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim DATACOUNTER As Integer
       With Text1
          On Error GoTo No_File_info
          For DATACOUNTER = 1 To Data.Files.Count
             .Text = .Text & Data.Files.Item(DATACOUNTER) & vbNewLine
          Next
       End With
    Exit Sub
    No_File_info:
       MsgBox "No File name from Explorer"
    End Sub

    Comment

    • blurryanthem
      New Member
      • Dec 2010
      • 43

      #3
      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!

      Comment

      • blurryanthem
        New Member
        • Dec 2010
        • 43

        #4
        It only showed the varchar sign to separate the selected files. I would want to display each selected dragged file into different textboxes.

        Comment

        • Guido Geurs
          Recognized Expert Contributor
          • Oct 2009
          • 767

          #5
          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 Files

          Comment

          • blurryanthem
            New Member
            • Dec 2010
            • 43

            #6
            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.

            Comment

            • blurryanthem
              New Member
              • Dec 2010
              • 43

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

              Comment

              • Guido Geurs
                Recognized Expert Contributor
                • Oct 2009
                • 767

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

                Comment

                • blurryanthem
                  New Member
                  • Dec 2010
                  • 43

                  #9
                  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.

                  Comment

                  • Guido Geurs
                    Recognized Expert Contributor
                    • Oct 2009
                    • 767

                    #10
                    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.

                    Comment

                    • blurryanthem
                      New Member
                      • Dec 2010
                      • 43

                      #11
                      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.

                      Code:
                      Private Sub Command1_Click()
                          Dim Det As Long
                          Det = Shell("explorer.exe /e, C:\", vbNormalFocus)
                      
                      End Sub
                      
                      Private Sub Command3_Click()
                      TextBox.Text = ""
                      End Sub
                      
                      Private Sub Form_Load()
                          TextBox.OLEDropMode = 1      '§ manual
                      End Sub
                      
                      Private Sub TextBox_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
                      
                      Dim i As Integer
                          Load Text1(DATACOUNTER)
                          With TextBox
                             For i = 1 To Data.Files.Count
                                .Text = .Text & Data.Files.Item(i) & vbNewLine
                             Next
                          End With
                       End Sub

                      Comment

                      • blurryanthem
                        New Member
                        • Dec 2010
                        • 43

                        #12
                        If there is a better way of doing it, I hope you could help. Thanks in advance.

                        Comment

                        • Guido Geurs
                          Recognized Expert Contributor
                          • Oct 2009
                          • 767

                          #13
                          If I'm right, it looks like in the attached GIF ?
                          Attached Files

                          Comment

                          • blurryanthem
                            New Member
                            • Dec 2010
                            • 43

                            #14
                            More or less like this too:



                            Here's the modified code though.


                            Code:
                            Option Explicit
                            
                            Private Sub ClearAllBtn_Click()
                            Text1.Text = ""
                            End Sub
                            
                            Private Sub OpenWEBtn_Click()
                                Dim Det As Long
                                Det = Shell("explorer.exe /e, C:\", vbNormalFocus)
                            End Sub
                            
                            Private Sub Form_Load()
                                DropArea.OLEDropMode = 1      '§ manual
                            End Sub
                            
                            Private Sub DropArea_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
                            Dim i As Integer
                            On Error GoTo No_File_info
                            For i = 1 To Data.Files.Count
                            Load Text1(i)
                                    With Text1(i)
                                        .Top = Text1(0).Top + i * (Text1(0).Height + 15)
                                        .Text = Data.Files.Item(i)
                                        .Visible = True
                                    End With
                                  Next
                                Exit Sub
                            No_File_info:
                               MsgBox "No File name from Explorer"
                            End Sub
                            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!

                            Comment

                            • Guido Geurs
                              Recognized Expert Contributor
                              • Oct 2009
                              • 767

                              #15
                              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).

                              Comment

                              Working...