Results 1 to 6 of 6

Thread: Listbox problem heeeelllllppp!

  1. #1

    Thread Starter
    Registered User
    Join Date
    Sep 2002
    Posts
    221

    Question Listbox problem heeeelllllppp!

    Hi

    Can anyone help me with this problem. In my program I have a single listbox which shows the full directory and file name of any file(s) dragged and dropped into the list box. the code is below:

    Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)

    Dim Files As Variant

    For Each Files In Data.Files

    List1.AddItem Files

    Next

    Effect = vbDropEffectNone

    End Sub

    How do I get the full path name and filename, e.g. c:\music\mp3\audio.wav (that path would be displayed if audio.wav in that directory was drag dropped into the listbox.

    How do I get that info into a txt file
    Last edited by jennysmith; Sep 28th, 2002 at 08:26 AM.

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    It's a bit difficult to undestand what exactly you need to do, however I will try:
    your code is loading List1 with files selected in explorer (for instance). And it works just fine. Now, if you need to send that list to a text file then the following code will do that:
    VB Code:
    1. Private Sub Command1_Click()
    2. '============================
    3. Dim i%
    4.  
    5.     Open App.Path & "\list.txt" For Output As #1
    6.         For i = 0 To List1.ListCount - 1
    7.             Print #1, List1.List(i)
    8.         Next i
    9.     Close #1
    10.  
    11. End Sub
    Note: if it's not what you need then please advise.
    Roy

  3. #3

    Thread Starter
    Registered User
    Join Date
    Sep 2002
    Posts
    221
    Hi Roy

    Thanks for your post. Your code is not exactly what I wanted to do. I want the information from the listbox to go into the text file as soon as it is dragged onto the listbox, and not by pressing a commandbotton.

    I hope what makes things a bit more clear.

    Thanks

  4. #4
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    IROY55 doesn't seem to be around at the moment so:

    VB Code:
    1. Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, _
    2.       Button As Integer, Shift As Integer, X As Single, Y As Single)
    3.    
    4.    Dim Files As Variant
    5.    Dim intFileNum as Integer
    6.  
    7.    intFileNum = FreeFile
    8.  
    9.    Open App.Path & "\list.txt" For Output As #intFileNum
    10.  
    11.    For Each Files In Data.Files
    12.       List1.AddItem Files
    13.       Print #intFileNum, Files
    14.    Next
    15.    Close #intFileNum
    16.  
    17.    Effect = vbDropEffectNone
    18. End Sub
    This works the same as IROY55's code, I just let VB assign the file number and moved the Print # statement into your For Each loop

  5. #5

    Thread Starter
    Registered User
    Join Date
    Sep 2002
    Posts
    221
    Thanks for replying John

    I tried it out and seems to work file but, It replaces lines in the test file.

    If I drag the file c:\music.mp3 to the listbox, that path is added to the text file, but if a then drag c:\mp3\audio.mp3, the first line is replaced with the new line in the text file.

    How do I keep the original paths in the text file and add the new paths under it?

  6. #6
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Jenny,
    if you don't want to override your file then instead of:
    Open App.Path & "\list.txt" For Output As #intFileNum
    use this:
    Open App.Path & "\list.txt" For Append As #intFileNum
    Roy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width