How to: Change User Settings in Visual Basic
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Change User Settings in Visual Basic 

You can change a user setting by assigning a new value to the setting's property on the My.Settings object.

The My.Settings object exposes each setting as a property. The property name is the same as the setting name, and the property type is the same as the setting type. The setting's Scope determines if the property is read-only: The property for an Application-scope setting is read-only, while the property for a User-scope setting is read-write. For more information, see My.Settings Object.


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.


This example changes the value of the Nickname user setting.

Sub ChangeNickname(ByVal newNickname As String)
    My.Settings.Nickname = newNickname
End Sub

For this example to work, your application must have a Nickname user setting, of type String. For more information, see How to: Add or Remove Application Settings.

The application saves the user settings when the application shuts down. To save the settings immediately, call the My.Settings.Save method. For more information, see How to: Persist User Settings in Visual Basic.

See Also

© 2015 Microsoft