Multiple Textboxes to one textfile
Hey Guys,
at first, sorry for this noob question but im pretty new in VB^^
So basically, i have a programm with two listboxes and i want that i can save the content of the listboxes to a txt file
(It should be like this:
Listbox1.Item1 + Listbox2.Item1
Listbox1.Item2 + Listbox2.Item2 etc)
Im currently at this point:
Code:
Dim sw As New System.IO.StreamWriter(SaveFileDialog1.FileName)
Dim i As Integer
For i = 0 To ListBox1.Items.Count - 1
sw.WriteLine(ListBox1.Items.Item(i))
Next
sw.Close()
I already tried different possibilities but never got it working :(
Would be cool if you guys can help me with this
Thanks in advance and sry for being a noob
Re: Multiple Textboxes to one textfile
try this:
Code:
dim sfd as new SaveFileDialog
if sfd.showdialog = dialogresult.ok then
IO.File.WriteAllLines(sfd.FileName, Enumerable.Range(0, ListBox1.Items.Count).Select(Function(x) String.Format("{0}, {1}", ListBox1.Items(x), ListBox2.Items(x))).ToArray)
end if
Re: Multiple Textboxes to one textfile
Quote:
Originally Posted by
.paul.
try this:
Code:
dim sfd as new SaveFileDialog
if sfd.showdialog = dialogresult.ok then
IO.File.WriteAllLines(sfd.FileName, Enumerable.Range(0, ListBox1.Items.Count).Select(Function(x) String.Format("{0}, {1}", ListBox1.Items(x), ListBox2.Items(x))).ToArray)
end if
Thank you very much :D
Re: Multiple Textboxes to one textfile
.paul. he said he is new to vb man. with code like this he's gonna hate us and vb
here is a simplified one
Code:
Dim s As New IO.StreamWriter("c:\path_to_file")
For i = 0 To ListBox1.count - 1
Dim data As String = listbox1.items(i)
s.WriteLine(Data)
Next
s.Close()
Re: Multiple Textboxes to one textfile
If the data is large enough it might even be better to avoid the LINQ. I enjoy LINQ, but there are places where a regular loop is sometimes better.