0

Good evening,

   I'm having problems when trying to save a listbox in a .txt file, follow the code;

IO.Directory.CreateDirectory("C:\Test")
         Dim Caminho As New IO.StreamWriter("C:\Test\Arquin.txt")
         Dim i As Integer
         For i = 0 To ListBox1.Items.Count - 1
                 Caminho.WriteLine(ListBox1.Items.Item(i))
         Next
         Caminho.Close()

The following error occurs:

'Item' is not a member of 'System.Array'

(I am Brazilian, maybe my English is half wrong because I used the google translator)

Edited by Reverend Jim: Corrected code formatting (we use markdown syntax)

4
Contributors
9
Replies
29
Views
1 Year
Discussion Span
Last Post by Reverend Jim
0

Created the file, but when I see has nothing recorded in the file

0

If there are string values the code line should be similar to listBox.Items[i].ToString() Try that.

0

A ListBox, by definition, contains text. You don't have to convert to String. Try replacing

Caminho.WriteLine(line)

with

Debug.WriteLine(line)

or put a breakpoint at that line and check the values. But don't forget to add

Caminho.Close()

after the loop.

Edited by Reverend Jim

0

It did not work ...

I think it is not working because I was wearing a theme in vb.net to change the appearance

0

Instead of Caminho.WriteLine(ListBox1.Items.Item(i)) use Caminho.WriteLine(ListBox1.Items(i)) which can return you the value of the lisboxitem at the position of i.

0

Did tests and found that the problem is that I was not going through the listbox, maybe it's because my listbox is of topics that I put in vb.net

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.