|
-
May 12th, 2013, 08:13 AM
#1
Thread Starter
Junior Member
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
-
May 12th, 2013, 08:54 AM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 12th, 2013, 09:24 AM
#3
Thread Starter
Junior Member
Re: Multiple Textboxes to one textfile
 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
-
May 12th, 2013, 09:49 AM
#4
New Member
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()
Last edited by mobarako; May 12th, 2013 at 09:59 AM.
-
May 12th, 2013, 07:23 PM
#5
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.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|