Tabcontrol into .txt

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

Tabcontrol into .txt
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
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Tabcontrol into .txt
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
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

Re: Tabcontrol into .txt
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
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Tabcontrol into .txt
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
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
CodenBoy
Top Poster
Top Poster
Posts: 103
Joined: Sun Jul 15, 2012 4:06 pm

Re: Tabcontrol into .txt
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!!!
5 posts Page 1 of 1
Return to “Coding Help & Support”