Dani Mateo
Dani Mateo

Reputation: 191

How to save settings made in VB?

Is there any way I can save changes made by a user , so that at the next run they would still be there? I have seen something about My.Settings , is that how it is done?

Upvotes: 7

Views: 16245

Answers (1)

Mark Hall
Mark Hall

Reputation: 54532

Yes you have multiple options, you can create a file and load it on startup, or you can use the built in settings object. Just go to your Project Property's --> settings set your variable there, the you can access it through My.Settings

enter image description here

Then load it like this:

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Dim greeting As String = My.Settings.mySetting
End Sub

you would change the value and save it like this

My.Settings.mySetting = "GoodBye"
My.Settings.Save()

Upvotes: 10

Related Questions