Skip to content

Instantly share code, notes, and snippets.

@riston
Created January 2, 2014 08:39
Show Gist options
  • Save riston/8216462 to your computer and use it in GitHub Desktop.
Save riston/8216462 to your computer and use it in GitHub Desktop.
Visual Basic, reading all text to string from file and writing
Imports
Imports System.IO
Imports System.Text
Public Class MainForm
Private filePath = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\settings.txt"
Private Sub Chart1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub MainForm_Disposed(sender As Object, e As EventArgs) Handles Me.Disposed
End Sub
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If File.Exists(filePath) Then
'File exists open file and set the settings
MessageBox.Show(File.ReadAllText(filePath))
End If
End Sub
Imports
Imports System.IO
Imports System.Text
Public Class MainForm
Private filePath = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\settings.txt"
Private Sub Chart1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub MainForm_Disposed(sender As Object, e As EventArgs) Handles Me.Disposed
End Sub
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If File.Exists(filePath) Then
'File exists open file and set the settings
MessageBox.Show(File.ReadAllText(filePath))
End If
End Sub
Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
Dim settingsString As String = "FirstSecondnThirdn"
File.WriteAllText(filePath, settingsString)
MessageBox.Show("Are you really closing?")
End Sub
End Class
Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
Dim settingsString As String = "FirstSecondnThirdn"
File.WriteAllText(filePath, settingsString)
MessageBox.Show("Are you really closing?")
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment