Reputation: 99
Is it possible with VB.2010 to create a 'save' file option that will save current app settings to a file and then be able to 'open' those setting. basically I am after implementing the traditional save, open feature in my drop down task bar.
When I say settings I mean a load of text box contents etc
Upvotes: 1
Views: 1462
Reputation: 992
You can store it in a text file, if it's not secure/confidential information.
This is just an example:
' For own file name or save place...
Dim sfd As New SaveFileDialog
sfd.ShowDialog()
Dim myPath As String = sfd.FileName
' Replace "My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\NAME_OF_FILE.txt" with "myPath"
' To save
FileOpen(1, My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\NAME_OF_FILE.txt", OpenMode.Output)
PrintLine(1, TextBox1.Text)
PrintLine(1, TextBox2.Text)
' And so on...
FileClose(1)
' To load
If My.Computer.FileSystem.FileExists(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\NAME_OF_FILE.txt") Then
FileOpen(1, My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\NAME_OF_FILE.txt", OpenMode.Input)
TextBox1.Text = LineInput(1)
TextBox2.Text = LineInput(1)
' And so on...
FileClose(1)
End If
Remember to always close the file, otherwise you'll get memory leaks and all sorts of nasty stuff =P
You can use FreeFile()
to get the next free file number, comes in use when opening multiple files...
This is a simple method, I'm sure you can use this as a template and implement it for your own use.
Hope it helps
Upvotes: 1