Hi all. I am coding a program and I want it to save what the user types in for next load up.

So for example...

User types 'hello' in texbox1
User closes program.
User opens program few days later.
User sees in textbox1 it says 'hello'

Any ideas how to do this?:)
(I done a quick search on daniweb and internet and found noting that worked)
(Sorry if i make no sense to, I don't know a good way to explain it:( )

Dani AI

Generated

Brief, practical summary and a few improvements to the suggestions already posted by and .

Prefer user-scoped settings (My.Settings) for simple per-user values and a small file under the current user profile for full control. Note that My.Resources (as suggested by ) is not for runtime persistence — resources are compiled into the assembly and are effectively read-only at runtime. 's file approach works but avoid hard-coding roots like C:\ (permission and portability problems).

Important My.Settings tips

  • Create the setting in Project -> Properties -> Settings and set Scope = User (Application scope is read-only at runtime).
  • Read the setting on startup and call My.Settings.Save() when persisting changes.
  • After an application upgrade, call My.Settings.Upgrade() once to migrate prior-version user settings.
  • Settings are stored per Windows user (no admin required) so they are appropriate for per-user preferences and small strings/collections.

Safer file-based approach (when a file is wanted)

  • Store files under the current user profile (AppData) and create the folder if missing.
  • Wrap writes/reads in try/catch to handle permission or disk errors.
  • Example pattern (VB): create AppData path, Directory.CreateDirectory(...), then WriteAllText/ReadAllText in try/catch.

Additional notes

  • For ’s checkbox idea: persist the checkbox state as a Boolean user setting and check it at startup to decide whether to restore text.
  • Avoid storing passwords or sensitive data in plain text; encrypt or use DPAPI if needed.
  • For frequent typing, consider a debounced save (timer) instead of saving on every keystroke to reduce disk churn.

These points fill gaps in the original replies and make the solution robust across machines and upgrades.

Recommended Answers

All 3 Replies

Member Avatar for Member #733618

Hello, i dont know how to use .INI for save something... but you can go to, my project, Resources, and complete in Name the Variable name, and in value the value to save. If you want to modify use My.Resources.YOURSTRINGNAME, but only you can read it.

Using .txt File.

Public Class Form1

    Private myCoolFile As String = "C:\test.txt" '// your file.

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        IO.File.WriteAllText(myCoolFile, TextBox1.Text) '// overwrite/create file.
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If IO.File.Exists(myCoolFile) Then '// check if file exists.
            TextBox1.Text = IO.File.ReadAllText(myCoolFile) '// load file content.
        End If
    End Sub
End Class

Using My.Settings.

From the vb.net top Menu, click Project and select yourApplication Properties...
Locate the Settings Tab and add
"valid" as your setting Name.

Serial number thread.

I created a String setting named "myCoolText".
Just make sure your Application has been previously saved.

Public Class Form1

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        My.Settings.myCoolText = TextBox1.Text
        My.Settings.Save()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = My.Settings.myCoolText
    End Sub
End Class

Or ApplicationSettings.
http://www.daniweb.com/forums/post1330523.html#post1330523

Thank you all so much!:D

I used the string method to save all the information using a checkbox. (if the checkbox is ticked then save info, if not then don't)

You both helped me and I thank you alot:D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.