Advertisement
kshadow22

#3 Creating Saving Option With Visual Basic

Mar 25th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form2
  2.     Dim UserTextBox1A As String = Nothing
  3.     Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  4.         Form1.WindowState = FormWindowState.Normal
  5.     End Sub
  6.  
  7.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8.  
  9.     End Sub
  10.  
  11.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  12.         If System.IO.File.Exists(Application.StartupPath & "\TextBox1.txt") Then
  13.             System.IO.File.Delete(Application.StartupPath & "\TextBox1.txt")
  14.             Dim objwriter As New System.IO.StreamWriter(Application.StartupPath & "\TextBox1.txt")
  15.             objwriter.Write(TextBox1.Text)
  16.             objwriter.Close()
  17.         Else
  18.             Dim objwriter As New System.IO.StreamWriter(Application.StartupPath & "\TextBox1.txt")
  19.             objwriter.Write(TextBox1.Text)
  20.             objwriter.Close()
  21.         End If
  22.     End Sub
  23.  
  24.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  25.         Dim SaveFile As New SaveFileDialog
  26.         SaveFile.FileName = ""
  27.         SaveFile.Filter = "Text Files (*.txt)|*.txt"
  28.         SaveFile.Title = "Save"
  29.         SaveFile.ShowDialog()
  30.         Try
  31.             Dim Write As New System.IO.StreamWriter(SaveFile.FileName)
  32.             Write.Write(TextBox1.Text)
  33.             Write.Close()
  34.         Catch ex As Exception
  35.  
  36.         End Try
  37.     End Sub
  38.  
  39.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  40.         If System.IO.File.Exists(Application.StartupPath & "\TextBox1.txt") Then
  41.             Dim objreader As New System.IO.StreamReader(Application.StartupPath & "\TextBox1.txt")
  42.             TextBox1.Text = objreader.ReadToEnd
  43.             objreader.Close()
  44.         Else
  45.             TextBox1.Text = ("No Content To Be Displayed")
  46.         End If
  47.     End Sub
  48.  
  49.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  50.         Dim OpenFile As New OpenFileDialog
  51.         OpenFile.FileName = ""
  52.         OpenFile.Filter = "Text Files (*.txt)|*.txt"
  53.         OpenFile.Title = "Open"
  54.         OpenFile.ShowDialog()
  55.         Try
  56.             Dim Read As New System.IO.StreamReader(OpenFile.FileName)
  57.             TextBox1.Text = Read.ReadToEnd
  58.             Read.Close()
  59.         Catch ex As Exception
  60.  
  61.         End Try
  62.     End Sub
  63.  
  64.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  65.         My.Settings.UserTextBox1 = TextBox1.Text
  66.         My.Settings.Save()
  67.     End Sub
  68.  
  69.     Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  70.         TextBox1.Text = My.Settings.UserTextBox1
  71.         If TextBox1.Text = Nothing Then
  72.             TextBox1.Text = "There Is No Content To Be Displayed"
  73.         End If
  74.     End Sub
  75.  
  76.     Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
  77.         UserTextBox1A = TextBox1.Text
  78.  
  79.     End Sub
  80.  
  81.     Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
  82.         TextBox1.Text = UserTextBox1A
  83.         If TextBox1.Text = Nothing Then
  84.             TextBox1.Text = "There Is No Content To Be Displayed"
  85.         End If
  86.     End Sub
  87. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement