Simple Text Editor Tutorial (for noobs)

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
5 posts Page 1 of 1
Contributors
User avatar
Jg99
VIP - Site Partner
VIP - Site Partner
Posts: 453
Joined: Sun Mar 20, 2011 5:04 am

Simple Text Editor Tutorial (for noobs)
Jg99
Hello this is Jamesgryffindor99 productions and i am presenting you a Simple Text editor tut
You Will Need:
1. a text box (Dock Fill)
a Menu Strip with under File are Open and Save As
Next, Double Click Open and put in the code below
Now, Here is the Code.
Code: Select all
Dim open As New OpenFileDialog()
 Dim mySreamReader As System.IO.StreamReader
 open.Filter = "[*.txt*]|*.txt|All Files[*.*]|*.*" 
open.CheckFileExists = True 
open.Title = "Open File"
 open.ShowDialog(Me)
Try
 open.OpenFile() 
mySreamReader = System.IO.File.OpenText(open.FileName) 
TextBox1.Text = mySreamReader.ReadToEnd() 
Catch ex As Exception
 End Try
Go back to the designer and double click on and put this code in
Code: Select all
Dim save As New SaveFileDialog() 
Dim myStreamWriter As System.IO.StreamWriter
 save.Filter = "(*.txt)|*.txt|All Files(*.*)|*.*"
save.CheckPathExists = True
 save.Title = "Save File" save.ShowDialog(Me)
 Try
 myStreamWriter = System.IO.File.AppendText(save.FileName)
 myStreamWriter.Write(RichTextBox1.Text)
 myStreamWriter.Flush()
 Catch ex As Exception 
End Try
Now you have a Simple Text Editor!
http://www.sctechusa.com SilverCloud Website
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

this is very basic, you should have called this tutorial something like "How to use OPEN & SAVE FILE DIALOG"
You can find me on Facebook or on Skype mihai_92b
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

[*.txt] is not really a description :/
and you can show a message when it failed so save so the user would know what's wrong

change
Code: Select all
Catch ex As Exception
End Try
to
Code: Select all
Catch ex As Exception
Msgbox(ex.Message)
End Try
And it's for noobs , you should really comment the code cooll;
http://vagex.com/?ref=25000
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

You can comment out the line open.OpenFile() unless you are going to use the StreamReader that it returns.
User avatar
Jg99
VIP - Site Partner
VIP - Site Partner
Posts: 453
Joined: Sun Mar 20, 2011 5:04 am

im using the stream reader
http://www.sctechusa.com SilverCloud Website
5 posts Page 1 of 1
Return to “Tutorials”