VB.NET gets the default value from My.Settings

VB2010. I understand how to save settings and load them from the My.Settings namespace. I am trying to figure out how to get the default value for the parameters and present it to the user. I do not want to save the settings, I just want to show what the current value is and what is the default value. I tried this, but I don’t think it is doing what I think should do:

 Msgbox "Current setting: " & My.Settings.CustLineWidth & vbcrlf & _
        "Default setting: " & My.MySettings.Default.CustLineWidth

By default, when I have a setting in the IDE, 10, but the user changed it to 25. If I run the code above, I get

 Current setting: 25
 Default setting: 25

I would like

 Current setting: 25
 Default setting: 10

Solution: I repeat all the settings and print the current value and a default value like this

        For Each prop As Configuration.SettingsPropertyValue In My.Settings.PropertyValues
            Debug.Print("Name={0}", prop.Name)
            Debug.Print("  Value  ={0}", prop.PropertyValue.ToString)
            Debug.Print("  Default={0}", prop.Property.DefaultValue.ToString)
        Next prop
+4
source share
3

:

My.Settings.PropertyValues("CustLineWidth").Property.DefaultValue
+3

:

MsgBox(CStr(My.Settings.Properties.Item("CustLineWidth").DefaultValue))

:

My.Settings.PropertyValues("CustLineWidth").Property.DefaultValue

"settings.save"::

My.MySettings.Default.CustLineWidth
0

Say you added this to your settings file, you just need to do something like below

My.Settings.YOUR_SETTING_NAME
0
source

All Articles