Results 1 to 4 of 4

Thread: [RESOLVED] [2005] Saving Texbox1.Text - TextBox10.Text to file.txt

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    6

    Resolved [RESOLVED] [2005] Saving Texbox1.Text - TextBox10.Text to file.txt

    Hello mates,

    Im new in VB programming. I'm using Visual Basic language to programm my test apz. So i have little question.

    Actually i can save TextBoxes like that text1text2 ... text10

    but I want that TextBox1.Text to TextBox10.Text save to file.txt with one way that the file.txt would be smth like that formating:

    text1
    text2
    text3
    ...
    text10

    And then i want to read all data in file.txt and put them back to the TextBoxes same order as they are in file.txt

    I will be waiting for helpful replay's

    Thanks

  2. #2
    Lively Member
    Join Date
    Jun 2004
    Posts
    94

    Re: [2005] Saving Texbox1.Text - TextBox10.Text to file.txt

    Code to write to file:

    Code:
    writer as TextWriter =new TextWriter("c:\temp\outputfile.txt");
    Dim textbox As TextBox
    
    
    foreach ctrl As Control in Me.Controls
    
    if typeof(ctrl) is TextBox then
    textbox = CType(ctrl, TextBox)
    writer.WriteLine(textbox.Text)
    end if
    
    next ctrl
    writer.Close()
    Code to read from file:

    Code:
    reader as TextReader =new TextReader("c:\temp\outputfile.txt");
    Dim textbox As TextBox
    
    
    foreach ctrl As Control in Me.Controls
    
    if typeof(ctrl) is TextBox then
    textbox = CType(ctrl, TextBox)
    textbox.Text=reader.ReadLine()
    end if
    
    next ctrl
    reader.Close()

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Saving Texbox1.Text - TextBox10.Text to file.txt

    vb Code:
    1. IO.File.WriteAllLines("file path here", _
    2.                       New String() {Me.TextBox1.Text, _
    3.                                     Me.TextBox2.Text, _
    4.                                     ... , _
    5.                                     Me.TextBox10.Text})
    vb Code:
    1. Dim lines As String() = IO.File.ReadAllLines("file path here")
    2.  
    3. Me.TextBox1.Text = lines(0)
    4. Me.TextBox2.Text = lines(1)
    5. ...
    6. Me.TextBox10.Text = lines(9)
    Last edited by jmcilhinney; Mar 18th, 2007 at 10:35 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    6

    Re: [2005] Saving Texbox1.Text - TextBox10.Text to file.txt

    Thanks jmcilhinney

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width