[TUT]Open & Close Text
How to open .txt files and how to save .txt files using textbox.
1. Open Visual Basic 2008 > Windows Forms Application.
2. Add 2 Buttons and 1 textbox (and opf and sfd)
3. It should now look something like this.
[IMG]http://i965.photobucke*****m/albums/ae133/MUSHIMOUSE/text.png[/IMG]
4. Double click on button1 and add this code.
[PHP]SaveFileDialog1.Filter = "text files (*.txt)| *.txt"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> Nothing Then
My.Computer.FileSystem.WriteAllText(SaveFileDialog 1.FileName, TextBox1.Text, False)
End If[/PHP]
5. Double click button2 and add this code.
[PHP]OpenFileDialog1.Filter = "text files (*.txt)| *.txt"
OpenFileDialog1.ShowDialog()
Dim fname As String = OpenFileDialog1.FileName
If System.IO.File.Exists(fname) Then
Dim read As New System.IO.StreamReader(fname)
TextBox1.Text = read.ReadToEnd
read.Close()
End If[/PHP]
6. Ok now debug to see if it works.
7. If it works then pat yourself on the back and serve yourself some ice tea because you just made a simple Open & Save .txt program:]