|
-
Sep 28th, 2002, 08:10 AM
#1
Thread Starter
Registered User
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.
-
Sep 28th, 2002, 09:28 AM
#2
PowerPoster
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:
Private Sub Command1_Click()
'============================
Dim i%
Open App.Path & "\list.txt" For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next i
Close #1
End Sub
Note: if it's not what you need then please advise.
-
Sep 28th, 2002, 03:19 PM
#3
Thread Starter
Registered User
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
-
Sep 28th, 2002, 03:33 PM
#4
Frenzied Member
IROY55 doesn't seem to be around at the moment so:
VB Code:
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
Dim intFileNum as Integer
intFileNum = FreeFile
Open App.Path & "\list.txt" For Output As #intFileNum
For Each Files In Data.Files
List1.AddItem Files
Print #intFileNum, Files
Next
Close #intFileNum
Effect = vbDropEffectNone
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
-
Sep 28th, 2002, 03:45 PM
#5
Thread Starter
Registered User
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?
-
Sep 28th, 2002, 04:35 PM
#6
PowerPoster
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|