Click to See Complete Forum and Search --> : How do i save the list from a listbox


David Lenk
October 22nd, 1998, 02:52 AM
how do i save the list from a listbox control?


i have a program that creates numbers and puts them into a listbox when they meet certain criteria. I need to be able to save this list..


is there a better way to list them than a listbox?


please help.

Felix Haas
October 22nd, 1998, 03:48 AM
Try this code:


dim i%


open "C:\bbb.txt" for output as #1


for i%=1 to list1.listcount-1

print #1,list1.list(i%)

next


close #1


------


That's it.


Felix

Jerome Norgren
May 8th, 2000, 12:04 PM
David

If you want to save it to a text file, I saw a post on microsoft.public.vb.general.discussion that may be what you want. I'll paste it in here but leave eveything (Their names etc...) in it as this isn't my solution! Hope it helps!

Jerome Norgren

<Paste>

Save listbox items to test file
From: Mike Carlson
Date Posted: 5/7/00 8:32:22 PM

Does anybody have any code samples for saving the items in a list box to a
text file using the common dialog controls?

Thanks,

Mike





Re: Save listbox items to test file
From: Randy Birch
Date Posted: 5/7/00 9:14:31 PM

Off the top of my head ...

private Sub Command1_Click()

on Local error GoTo ohmygodtheidiothitcancel

Dim c as Long
Dim hFile as Long

With CommonDialog1

.CancelError = true
.InitDir = "d:\"
.FileName = "untitled.txt"
.Filter = "Text File;*.txt"

.ShowSave

If len(.FileName) then

MsgBox .FileName

hFile = FreeFile
Open .FileName for Output as #hFile

for c = 0 to List1.ListCount - 1

print #hFile, List1.List(c)

next

Close #hFile

End If 'If len(.FileName)

End With 'CommonDialog1

outtahere:
Exit Sub

ohmygodtheidiothitcancel:

MsgBox "User pressed cancel - do nothing"
resume outtahere

End Sub



--
Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/
news://news.mvps.org/