Results 1 to 2 of 2

Thread: My.Settings problems

  1. #1

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    My.Settings problems

    1. I can't find the file which reflects changes to user settings. This might be because I just can't find it (I can see a bunch of user.config files but they are all empty - weird!), or ...

    2. I'm not actually saving them when I think I am.

    Regarding 2. - do I need to invoke
    Code:
    My.Settings.Save()
    immediately after every change that is made to the settings , or can I just rely on the settings being saved automatically when the application ends?

    I have this code in Settings.Designer.vb :-
    Code:
    Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
            If My.Application.SaveMySettingsOnExit Then
                My.Settings.Save()
            End If
        End Sub
    Is this all I need? And if so, why are my user.configs empty?
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: My.Settings problems

    By default, settings are automatically saved when the application exits. It's only if you uncheck that option in the project properties that you need save explicitly. Some people like to save explicitly after a change anyway, in case the application doesn't exit properly. If you handle the UnhandledException event of the application, the only reason that might happen is a power failure.

    I'm not sure what you're doing wrong but I just created a test app with a String setting and an Integer setting, ran it, changed the values and then closed it. I then clicked the Synchronize button I mentioned to get the user config file path. When I navigated to that location, I found the new values. I suggest that you do the same, i.e. create a test project and add nothing other than a couple of settings and some code to the form's Load event handler to change them.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width