You are here:

Visual Basic/save two text b.

Advertisement


Question
Dear Vitaly
I want to ask you if you can help me with this code below. This code, save and open a text box (TB1) to a file. My problem is that I can save 2 text boxes (TB1 and TB2) to a file

Thank you for your help
         Dimitris

Private Sub btsavel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btsavel.Click
     

       Dim FileWriter As StreamWriter
       Dim results As DialogResult
       results = savetext.ShowDialog()
       If results = DialogResult.OK Then
         FileWriter = New StreamWriter(savetext.FileName, False)

         FileWriter.Write(tb1.Text)
         
         '  FileWriter.Write(tb2.Text)

         FileWriter.Close()

       End If
End Sub


   Private Sub btopenl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btopenl.Click

       Dim FileReader As StreamReader
       Dim results As DialogResult
       results = Open.ShowDialog
       If results = DialogResult.OK Then
         FileReader = New StreamReader(Open.FileName)
         
         tb1.Text = FileReader.ReadToEnd()
        
        '   tb2.Text = FileReader.ReadToEnd()

         FileReader.Close()
       End If

End Sub

Answer
Dear Dimitris,

Please, check this link:

http://www.homeandlearn.co.uk/net/nets8p5.html

It has sample code which you can modify according to your needs.

As always, you need to study the code, understand how it's working and then use changed version in your code.

Regards,

Vitaly

Visual Basic

All Answers


Answers by Expert:


Ask Experts

Volunteer


VITALY

Expertise

Area of expertise is Visual Basic .NET (VS 2008 and Framework 3.5) design and development for Windows applications. You can ask me any Visual Basic questions and some questions about .NET Framework. You can also ask me how to use Component One controls in Visual Basic. Do not ask me questions about Web design and development in Visual Basic.

Experience

I'm working as VB programmer from 1997, so I have a lot of experience with Visual Basic .NET as well as Visual Basic 6. Area of expertise is Visual Basic .NET (VS 2008 and Framework 3.5) design and development for Windows applications; Component One controls for Visual Basic; User controls; Moving VB6 applications to .NET.

Education/Credentials
B.S. in Computer Science

©2016 About.com. All rights reserved.