VB.NET My.Settings
Want to store some user settings in vb.net?This could be used for any number of things, I used this to store the length of a barcode that was being read from a text file, the user could change the default of 12 to any custom value:
Â
Open My Project / Settings
Name = message
Type = integer
Scope = user
Value = 10
Add this code below our Public Class:
Public Sub New()
‘ This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
On you form load add (to display the value):
Try
txtbox1.text = My.Settings.message
Catch ex AsException
MsgBox(ex.Message)
End Try
Â
To Update the setting(put this on a button, reads new value from textbox):
Try
My.Settings.message = CInt(txtNewValue.Text)
My.Settings.Save()
My.Settings.Reload()
Msgbox(”New Setting Saved.”)
Catch ex As Exception
MsgBox(ex.Message)
End Try