Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2015. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: Text Editor
- '
- ' Author: Joseph L. Bolen
- ' Date Created: Feb 2015
- '
- ' Description: Simple plain text editor program with printing ability.
- '
- ' Documentation is at:
- ' App's screen image is at: http://imgur.com/TzWs9kO
- ' App's screen design time specs at: http://pastebin.com/bhinRQ5d
- ' App's Visual Basic .NET Event Procedures & TODO's is at
- ' http://pastebin.com/UZ4tcEpE
- ' App's Visual Basic .NET code is at http://pastebin.com/u/jaybeeoh
- ' Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
- '-------------------------------------------------------------------------------------------
- Imports System.IO
- Imports System.Security
- #Region " Declare Class Level Variables"
- Public applicationTitle As String = My.Application.Info.Title
- Private Const fileFilter As String =
- "Plain Text (*.txt)|*.txt|" &
- "Log Files (*.log)|*.log|" &
- "All Files (*.*)|*.*"
- Private workingPathFile As String = String.Empty
- Private workingPath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments
- #End Region
- ' File Save option.
- Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) _
- Handles SaveToolStripMenuItem.Click, SaveToolStripButton.Click
- ' If there is a valid file name, save file. Otherwise follow Save As logic.
- If (workingPathFile <> String.Empty) AndAlso
- (workingPathFile.EndsWith(".txt") OrElse workingPathFile.EndsWith(".log")) Then
- SaveFile()
- Else
- SaveAsToolStripMenuItem_Click(sender, e)
- End If
- End Sub
- ' File Save As option.
- Private Sub SaveAsToolStripMenuItem_Click(sender As Object, e As EventArgs) _
- Handles SaveAsToolStripMenuItem.Click
- ' Use the Save File Dialog to get the file name, then save file.
- With SaveFileDialog1
- .Filter = fileFilter
- .DefaultExt = "txt"
- If workingPathFile = String.Empty Then
- .FileName = "Document.txt"
- .InitialDirectory = workingPath
- Else
- .FileName = Path.GetFileName(workingPathFile)
- .InitialDirectory = Path.GetDirectoryName(workingPathFile)
- End If
- If DialogResult.OK = .ShowDialog Then
- workingPathFile = .FileName
- SaveFile()
- End If
- End With
- End Sub
- ' Write from Textbox's text property the data to a file using My.Computer.FileSystem.
- Private Sub SaveFile()
- Try
- My.Computer.FileSystem.WriteAllText(workingPathFile, MyTextBox.Text, False, System.Text.Encoding.UTF8)
- MyTextBox.Modified = False
- MyTextBox.Focus()
- workingPath = Path.GetDirectoryName(workingPathFile)
- Me.Text = applicationTitle & " - " & Path.GetFileName(workingPathFile)
- Catch ex As IOException
- MessageBox.Show(ex.Message, "File IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Catch ex As SecurityException
- MessageBox.Show(ex.Message, "File Permissions Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Catch ex As Exception
- MessageBox.Show("There was a problem saving the file." &
- ControlChars.NewLine & ex.Message,
- "Error Saving File",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error)
- End Try
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment