How to: Persist User Settings in Visual Basic

You can use the My.Settings.Save method to persist changes to the user settings.

Typically, applications are designed to persist the changes to the user settings when the application shuts down. This is because saving the settings can take, depending on several factors, several seconds.

For more information, see My.Settings Object.

Note

Although you can change and save the values of user-scope settings at run time, application-scope settings are read-only and cannot be changed programmatically. You can change application-scope settings when creating the application, through the Project Designer, or by editing the application's configuration file. For more information, see Managing Application Settings.

Example

This example changes the value of the LastChanged user setting and saves that change by calling the My.Settings.Save method.

Sub ChangeAndPersistSettings()
    My.Settings.LastChanged = Today
    My.Settings.Save()
End Sub

For this example to work, your application must have a LastChanged user setting, of type Date. For more information, see Managing Application Settings.

See Also

Tasks

How to: Read Application Settings in Visual Basic

How to: Change User Settings in Visual Basic

How to: Create Property Grids for User Settings in Visual Basic

Reference

My.Settings Object

Concepts

Managing Application Settings