Page 1 of 1

Tabcontrol into .txt

Posted: Sat Aug 11, 2012 7:22 pm
by CodenBoy
Hello, i thought im out of needing help and this is my last help for this minute LOL,

Im trying to do (below) but cant, anyone can help please loove; cooll;

( i will explain what i want in 2 ways so u can understand it xD )

First way:

Can u change this code to all the tabpages instead of selected only? idk how to do it like For Each I ... xD
Code: Select all
        Dim writer As New IO.StreamWriter("C:\Folder\" & TabControl1.SelectedTab.Text & ".txt")
        writer.Write(CType(TabControl1.SelectedTab.Controls.Item(0), TextBox).Text)
        writer.Close()
< how to make this code work for all tabpages? i mean 1 click i want all to be done tabpage 1 and 2 and 3 .. etc

Second way

I mean if u dont understand the thing in trying to do, this is another expalination xD,

I want to click a button, then ALL TabPages in tabcontrol1 will be saved (.txt) in a folder "C:/Folder" and with name of the selected tab name, also, the way im doing my old code is
Code: Select all
CType(TabControl1.SelectedTab.Controls.Item(0), TextBox).Text
this code will work if it was for multiple

Thanks

Re: Tabcontrol into .txt

Posted: Sat Aug 11, 2012 7:54 pm
by MrAksel
Code: Select all
For Each page As TabPage In TabControl1.TabPages
   Dim writer As New IO.StreamWriter("C:\Folder\" & page.Text & ".txt")
   writer.Write(CType(page.Controls.Item(0), TextBox).Text)
   writer.Close() 
Next

Re: Tabcontrol into .txt

Posted: Sat Aug 11, 2012 8:18 pm
by CodenBoy
Thanks #MrAxel , i actually wanted also to load them back, this is harder i know :D

This worked great, now i just wanna load them back with the text?

Thanks

Re: Tabcontrol into .txt

Posted: Sat Aug 11, 2012 8:39 pm
by MrAksel
Code: Select all
For Each file As String In System.IO.Directory.GetFiles("C:\Folder")
   Dim page As New TabPage()
   page.Text = Path.GetFileNameWithoutExtension(file)
   Dim box As New TextBox()
   box.Text = System.IO.File.ReadAllText(file)
   page.Controls.Add(box)
   TabControl1.TabPages.Add(page)
Next

Re: Tabcontrol into .txt

Posted: Sat Aug 11, 2012 9:56 pm
by CodenBoy
#MrAskel :D u r so awesome!, both worked, it took me 20 minutes to figure out that i should put imports system.io LOOL :D thanks

thanks!

thhxx +rep!!!