简体   繁体   中英

when trying to save listbox items to text file i get error

so i am tring to make all of listbox1 items to a text file and i keep getting the error "'item' is not a member of 'String()'"

where i get the error: w.WriteLine(ListBox1.items.Item(i))

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        IO.Directory.CreateDirectory("C:\ProxyGrabber")
        Dim w As New IO.StreamWriter("C:\ProxyGrabbe\test.txt")
        Dim i As Integer
        For i = 0 To ListBox1.items.Count - 1
            w.WriteLine(ListBox1.items.Item(i))
        Next
        w.Close()
    End Sub
ListBox1.items.Item(i)

returns an object type. If the listbox items are simply strings, all you need to do is change

w.WriteLine(ListBox1.items.Item(i))

to

w.WriteLine(CType(ListBox1.Items.Item(i), String))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM