save settings of application-VBForums
Results 1 to 11 of 11

Thread: save settings of application

  1. #1

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,042

    save settings of application

    Hi.
    I'm used to keep values in sql or files.

    I need to know how can i save settings on an application config file or my.settings and keep the values when i close the app,
    as I've read that these are read only and you need to change the files by hand.

    Thanks.
    Slow as hell.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,855

    Re: save settings of application

    When you add an item on the Settings page of the project properties, it becomes accessible via My.Settings. You can specify the scope to be Application or User. Application scope means that the value is stored in the main config file and the property of My.Settings is read-only. User scope means that the default value is stored in the main config file while the current value is stored in a separate config file for each Windows user and the property of My.Settings is read/write. By default, User-scoped settings will be saved automatically at shutdown.

    In short, add a setting with User scope and you're good to go, although each Windows account will have its own value for that setting.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,042

    Re: save settings of application

    Hi.
    Can't get this to work.

    OK so I save the settings fine but the problem here is that the settings must start initially from a settings.settings properties, so the initial values of the settings.settings are in user scope and I modify them trough the VS properties.
    But that is about it, the settings.settings properties never change.
    So what I need to do is
    1)At first run, get the default settings.settings properties (that I will not get with mysettings.default)
    2)Change them

    If i can't change them then that is a problem.
    How would I go to get the default settings at the very first run of the application and then save them and never get the defaults again?

    Thanks.
    Slow as hell.

  4. #4

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,042

    Re: save settings of application

    OK.
    Since I can't change the default settings.settings from the application, I switched to changing the configuration file by hand.
    This is not a preferred option though.

    I would like to have the settings.settings file changed from inside the application and it does not work.
    Or change the application config file.

    Or if that is not possible I would just create my own xml file and have the settings changes in there and be done with it , but that is extra job i though i could avoid.
    Slow as hell.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,188

    Re: save settings of application

    What? Some of this isn't making sense. If the setting is a User-scoped setting, you can change it... I'm not sure what the problem is in your case. Maybe if you showed some code where you're setting the settings and saving them, it'll become clear what the problem is.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Fanatic Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    576

    Re: save settings of application

    Quote Originally Posted by sapator View Post
    OK.
    Since I can't change the default settings.settings from the application, I switched to changing the configuration file by hand.
    This is not a preferred option though.

    I would like to have the settings.settings file changed from inside the application and it does not work.
    Or change the application config file.

    Or if that is not possible I would just create my own xml file and have the settings changes in there and be done with it , but that is extra job i though i could avoid.
    The application settings file resides in the same folder as the executable, if this is under program files then you shouldn't be saving changes there anyway (assuming you even have permissions to do so). This file is intended to be used as more of an administrative configuration tool and not meant for user settings.

  7. #7
    New Member
    Join Date
    Apr 2017
    Posts
    15

    Re: save settings of application

    Can you not write the settings to the User area in the Registry?

    This may help different users on the same machine or if your application was to run in a thin client environment (either RDP or Citrix).

    Carl.

  8. #8

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,042

    Re: save settings of application

    Hi.
    Now I removed everything so I'm not 100% sure for the code but it was probably
    my.settings.ThesettingName = "Value"
    mysetting.save .

    something close to that.

    So opening the properties of settings, the values do no change.
    CAUTION! The values actually change if you get them in code like dim x = my.settings.ThesettingName but they are not in the settings.settings properties.
    I read that these are the default values and the settings are saved somewhere else?
    I need to change the default values.
    Well actually I don't now. I changed everything to xml but for academic knowledge. Is this doable?
    Thanks.

    Ah.
    The frameworks is 4.0 as I saw some deprecated configurations there.If that makes a difference.
    Slow as hell.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,188

    Re: save settings of application

    Quote Originally Posted by sapator View Post
    Hi.
    Now I removed everything so I'm not 100% sure for the code but it was probably
    my.settings.ThesettingName = "Value"
    mysetting.save .

    something close to that.

    So opening the properties of settings, the values do no change.
    CAUTION! The values actually change if you get them in code like dim x = my.settings.ThesettingName but they are not in the settings.settings properties.
    I read that these are the default values and the settings are saved somewhere else?
    I need to change the default values.
    Well actually I don't now. I changed everything to xml but for academic knowledge. Is this doable?
    Thanks.

    Ah.
    The frameworks is 4.0 as I saw some deprecated configurations there.If that makes a difference.
    Wait... are you opening the settings designer in the IDE and expecting to see your changed values? That might be the issue. You WON'T see the changes there. Why would you? The designer writes the [project].settings file... that's the default design-time values. When you build, the .settings file is renamed to [application].exe.config and moved to the project output folder. When you run the app, it will load this .config file to get the default settings, THEN it will load the [application].user.config file which is stored IN THE USER'S PROFILE somewhere and overlay those values on to the ones from the [application].exe.config file... so only the user settings will then change. That's all there is to it (there's more involving the machine.config and web.config in some cases, but are irrelevant in this case).

    Code:
    my.settings.ThesettingName = "Value"
    mysetting.save
    That's how it's supposed to be. It's that simple.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,028

    Re: save settings of application

    If you start reading this document then keep following the links at the end, you'll get more in an hour than we'll get out of a lot of back-and-forth.

    To some extent you might not see them work like you expect in Visual Studio because the idea is the values you set in the IDE are default values, which are always the "first" values your program has. When you are developing the program, every time you build and run is sort of like a "new install", so it might reset your settings file. If you want to test settings, it's best to run the application outside of Visual Studio, or make sure you don't do clean builds/builds at all between test sessions.
    Nothing I post is production-ready. It is provided as-is, use it at your own risk.

  11. #11

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,042

    Re: save settings of application

    Hmm.
    Yes that is the issue.
    I want a file that is changing and the problem is that I might have to move the application in various computers so I need the settings to change not per user but per application.
    So when i move the app, i do not want to have the default settings but the, sort of, changed default settings.
    I have done that with an xml file that resides in the app folder an is changing from the app.

    So I guess if i need to maintain the settings someone sets for every location I can't do that with my.settings (?)

    Thanks.
    Slow as hell.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.