Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recording files

Status
Not open for further replies.

domt

Programmer
Mar 13, 2001
115
0
0
US
I have a list box (List3) with several items in it.
I want to store them in a text file on my C drive.
The following does not work.

fnum = FreeFile()
Open "C:\Stores.txt" For Output As #fnum
For Ct1 = 0 To List3.ListCount - 1
Write #fnum, List3.List(Ct1)
Next
Close fnum

Can anyone tell me what's wrong?
Any help will be appreciated.

Doug
 
Are you sure you are using a ListBox? ListCount is not a property of the .Net ListBox control. Maybe that's your issue. Anyways, here's some code to write your file:

Code:
        Dim s As String = ""
        For i As Integer = 0 To List3.Items.Count - 1
            s &= List3.Items(i).ToString & ControlChars.CrLf
        Next
        System.IO.File.WriteAllText("C:\Stores.txt", s)
 
RiverGuy
Thanks for your response.
I'm sorry that I forgot to say that I'm using VB6,
not VB .net
Have you got a fix for that?
Doug
 
I tried that code, and it works for me.

I also noticed that it puts quotes around the data, with each list item on a separate row. If you want to remove the quotes....

Code:
fnum = FreeFile()
Open "C:\Stores.txt" For Output As #fnum
For Ct1 = 0 To List3.ListCount - 1
  [!]Print[/!] #fnum, List3.List(Ct1)
Next
Close fnum

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you gmmastros
I don't know why, but it does not work for me.
Either using "Write" or "Print"
Doug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top