Anyone have a good routine to capture the contents of a list box and dump it to a text file ?
EG: I need to capture the actual displayed data of a listbox, not just selected items, but all items.
Printable View
Anyone have a good routine to capture the contents of a list box and dump it to a text file ?
EG: I need to capture the actual displayed data of a listbox, not just selected items, but all items.
Or do you mean a listbox from any application and not only your own?Code:Public Sub SaveLBContents(lstBox As ListBox, FileName As String)
Dim iFile%, i%, iCount%
iCount = lstBox.ListCount - 1
iFile = FreeFile
Open FileName For Output As #iFile
For i = 0 To iCount
Print #iFile, lstBox.List(i)
Next
Close #iFile
End Sub
Getting all the items in a list is easy, you just loop through them,
will put up a message for every item in the list, I'm not too hot on file handling, but there's some good tutorials HereCode:Private Sub Command1_Click()
For i = 0 To List1.ListCount - 1
MsgBox List1.List(i)
Next i
End Sub
[Edited by Sam Finch on 08-24-2000 at 11:22 AM]
Thanks Sam, and once again Joacim thanks. Both replies were very useful, one of my co-workers has absconded with all my vb manuals as well as my MSDN discs so I couldn't find the syntax.