Post[TUT]Open & Close Text

Posts 110 of 10 · Page 1 of 1
[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.

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:]
Me.Text = System.IO.Path.GetFileNameWithoutExtension(Openfil edialog1.FileName)
Quote Originally Posted by /b/oss View Post
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]
OpenFileDialog1.Filter = "text files (*.txt)| *.txt"
If Not OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1 .Filename)
End If

Quote Originally Posted by /b/oss View Post
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:]
Quote Originally Posted by Hassan View Post
xD you already did it :P
why is it always you posting this small stuff? =\
Quote Originally Posted by 'Bruno View Post
why is it always you posting this small stuff? =\
be happy -.-"
Very very simple tut. Thanks for sharing anyways.
This is not really a tutorial, you should have posted this in the snippet vault IMO.
Simple
But good job.
Posted in snippet vault.
Posts 110 of 10 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?