Visual Basic Text Editor

In this tutorial we will create a simple Text Editor using Visual Basic. This application that we create can perform a functions such as creating new documents by writing in the text field, modifying, deleting, searching, saving clear texts and finding texts within the text editor. It has a menu options that can import file, save, save as, and a exit button.

Sample Code

Import File - This code is for the importing of files from the explorer or the computer.
  1.         Dim fo As New OpenFileDialog
  2.         fo.Filter = "Text Files|*.txt"
  3.         fo.FilterIndex = 1
  4.         fo.ShowDialog()
  5.         If (fo.FileName = Nothing) Then
  6.             MsgBox("No file selected.")
  7.         Else
  8.             path = fo.FileName
  9.             Using sr As New StreamReader(fo.FileName)
  10.                 RichTextBox1.Text = sr.ReadToEnd()
  11.             End Using
  12.         End If
Save - And for the save function of files from the text editor.
  1.         If (Not path = Nothing) Then
  2.             Using sw As New StreamWriter(path)
  3.                 sw.Write(RichTextBox1.Text)
  4.             End Using
  5.         End If
Save As - For the save as function if you want it to save to another directory and another name.
  1.         Dim fs As New SaveFileDialog
  2.         fs.Filter = "Text Files|*.txt"
  3.         fs.FilterIndex = 1
  4.         fs.ShowDialog()
  5.         If (Not fs.FileName = Nothing) Then
  6.             Using sw As New StreamWriter(fs.FileName)
  7.                 sw.Write(RichTextBox1.Text)
  8.             End Using
  9.         End If
Hope that you learn from this tutorial and don't forget to Like & Share this project and the website. Enjoy Coding...!

Add new comment