Write all values from a listbox or file listbox to a text file - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Closed Thread
 
Thread Tools Display Modes
 
Old 08-20-2004, 07:53 PM   #1 (permalink)
Banned
 
Join Date: Aug 2004
Posts: 50
Exclamation Write all values from a listbox or file listbox to a text file

I have managed to retrieve all files from a directory and insert them into a file list box or a listbox but I am having problems writing each song title to a text file, any visual basic code examples would be very much appreciated !!

Thank you
__________________

__________________
gecko_au2003 is offline  
Old 08-21-2004, 08:17 AM   #2 (permalink)
Banned
 
Join Date: May 2003
Posts: 105
Default

Dim fso, fldTemp, LogFile, strFile, fObj
'Create a fs scripting object to hold the temp file
Set fso = CreateObject("Scripting.FileSystemObject")
strFile = "c:\outfile.txt"

If Dir(strFile) = "" Then
Set LogFile = fso.CreateTextFile(strFile, False)
Else
Set fObj = fso.GetFile(strFile)
Set LogFile = fObj.OpenAsTextStream(8) 'ForAppending)
Set fObj = Nothing
End If

LogFile.writeline TextToWrite

LogFile.Close


'dealloc objs
Set LogFile = Nothing
Set fldTemp = Nothing
Set fso = Nothing
__________________

__________________
_Jack is offline  
Old 08-21-2004, 12:06 PM   #3 (permalink)
Banned
 
Join Date: Aug 2004
Posts: 50
Default

where do i insert this coding, into a command button or a module ?
__________________
gecko_au2003 is offline  
Old 08-21-2004, 02:08 PM   #4 (permalink)
Banned
 
Join Date: May 2003
Posts: 105
Default

The code I posted will write the vaule of the variable "TextToWrite" to the file identified by the variable strFile.

You can put it behind a button or in a module as a sub and call that sub from what ever event inits the writing of the data to the file. Be sure to set the TextToWrite to the data you want written out and strFile to the path and name of the file (e.g., c:\myDir\MyFile.txt )
__________________
_Jack is offline  
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 06:35 PM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2019, vBulletin Solutions, Inc.