Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
VB.NET opening and saving text in a text file?
i have 4 text boxes (txt1, txt2, txt3 and txt4), 2 buttons (cmdupdate and cmdexit)
ive been looking all over the internet, but with no luck
i need some code that automatically saves the text in the 4 text boxes to either a .txt or .ini file, when the application is closed, or the text boxes are modified. then i want the values to be in their respective text boxes when the application is re-opened.
ie, the values in the 4 text boxes are there when the ap closes and are there again when its opened again
remember its VB.NET please
1 Answer
- MarkGLv 71 decade agoFavorite Answer
The current way to do this in Dot Net is to use a Settings which is defined in the projects properties on the Settings tab. Text files and ini files are old school and are depreciated means of persisting data.
Go to Project>"[Project Name] Properties
On the pop up select the Settings Tab
You will see a data grid. Type the name of the setting like Text1" for example. Value is a default value you can put something in this spot or leave it blank. Leave type as string and scope as user
To use you read the setting when the form loads and place the setting in the text box.
When you close the form or click a save button you place code that take the contents of the text box and places it into the setting then call a settings save method to write the setting to a file on the hard drive that is in the application folder for your project
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
My.Settings.Text1 = Me.TextBox1.Text
My.Settings.Save()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.TextBox1.Text = My.Settings.Text1
End Sub