saving to text file

qwertyjustin
09-08-2000, 01:01 PM
i have a list box called lstnames, and i would like to add this into a text file(hof.txt) after pressing cmdsave;)

what would the code for this be?????


thanx

BillSoo
09-08-2000, 01:16 PM
Your post is a little unclear; let me paraphrase what I *think* you mean:

How do you save the contents of a listbox to a text file?

Private Sub SaveList(lb as ListBox,fn as string)
Dim i%, ff%
ff% = FreeFile
Open fn For Output As #ff%
For i%=0 to lb.ListCount - 1
Print #ff%, lb.List(i%)
Next i%
Close #ff%
End Sub

Of course, there is no error checking in this function. You will need to handle all sorts of possible file errors, from no available space to drive unavailable to invalid filename etc.

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

Dazz
09-08-2000, 01:20 PM
The easyest way would be to dump the data into a sequencial file. If you want to just put it into a file you would need to open a file :-
Open "C:Hof.txt" for Output as #1
Or if you want to add the data to the bottom of a file :-
Open "C:Hof.txt" for append as #1

Then it is just a case of printing the data to the file :-
For x=1 to lstNames.ListCount-1
Print #1, lstnames.ListIndex(x)
next
Close #1

Hope it helps !

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum