Results 1 to 8 of 8

Thread: [RESOLVED] Carrying My.Settings (Config File)

  1. #1

    Thread Starter
    Lively Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Kentucky
    Posts
    95

    Resolved [RESOLVED] Carrying My.Settings (Config File)

    My program I am working on depends on the my.settings to store information and then retrieve it back when the program starts up. My.settings from my understanding is stored in a configuration file locally on each computer. This creates a huge issue for me because my program is to be used on a flash drive from computer to computer by the same user. The issue is that the my.settings are reset anytime the user changes or the computer changes. I need a work around to where, if possible, to keep using my.settings and store the config file within the application path and open the same config file nomatter the user or computer. I am open to all ideas and any help would be apprecaited.

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

    Re: Carrying My.Settings (Config File)

    Any settings with Application scope are read-only via My.Settings and are stored in the main application config file, which is stored in the same folder as the EXE. Default values for settings with User scope are also stored in the main config file with the current values stored for each Windows user under that user's personal folder. You can't really do anything about that because they have to be stored per user in order to provide different values per user.

    One option for you may be to handle the Shutdown event of your application and save all the current values for the User-scoped settings to a text file in the program folder. If your app is installed to Program Files then that may not be possible for a non-admin user but there will probably be no issues saving to a flash drive. You can then also handle the Startup event and look for that file, loading the values into My.Settings if you find it.
    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

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

    Re: Carrying My.Settings (Config File)

    I was going to provide an example of what I suggested above but then I started to think that there probably wasn't much point. If you were going to do as I suggested then you wouldn't really be getting much - if any - benefit from using My.Settings in the first place. You probably may as well just store your own settings in your own file and save and load from there every time.
    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

  4. #4

    Thread Starter
    Lively Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Kentucky
    Posts
    95

    Re: Carrying My.Settings (Config File)

    Right, that was what I was thinking as well. The conveniency of being able to use the user / application settings is nice, however, it does not provide what I need in this case which is dissapointing. Even more so because I relied on it after I typed up my entire program. Which is the reason why I was hoping for a work around. Thanks for your help!

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

    Re: [RESOLVED] Carrying My.Settings (Config File)

    Another option would be to use My.Settings but only use Application-scoped settings and edit/save them a bit more manually. You can follow the CodeBank link in my signature and check out my thread on Protected Configuration for an example of how to do that.
    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

  6. #6
    Banned
    Join Date
    Apr 2018
    Location
    https://t.me/pump_upp
    Posts
    79

    Re: [RESOLVED] Carrying My.Settings (Config File)

    I am having the same issue, but for a different reason. I need to use the info saved in several my.settings listof(string) in a different application. I only resorted to using My.Settings because I can't wrap my head around setting up a database or .xml file or ini.file. I'll be reading the suggested thread, but I'd rather use a database.

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

    Re: [RESOLVED] Carrying My.Settings (Config File)

    Quote Originally Posted by Amerigoware View Post
    I'd rather use a database.
    Then you should use one. It's not difficult and there are lots of resources around to help learn, e.g. Home & Learn. It's rare that a developer can get too far these days without knowing how to work with databases, unless you stick to very small-scale projects. If the amount of data is very small then you might just use a DataTable persisted to an XML file. You can simply add columns to a DataTable and call WriteXml on it to produce an XML file with the appropriate schema. Once you have that file, you can call ReadXml to load schema and data into a new DataTable and WriteXml to save any changes.
    Last edited by jmcilhinney; Dec 26th, 2018 at 12:40 AM.
    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

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Carrying My.Settings (Config File)

    You can use a configuration file, just not My.Setings.... you can use the ConfigurationManager to loadf/save to alternate configuration files outside the Application.Config and User.Config and to a location of your choice. It's been a LONG time since I've done it and I don't have anything handy to offer up as an example, but I'm sure if you search for ConfigurationManager you should be able to find something on it. If I remember right, it does take some additional effort to get it set up correctly, since you have to create some custom classes to hold the settings values, but in the end if it accomplishes the goal, it's worth it. I las used it 6 or 7 years ago to store alternate database connection information for a pet project I was working on that I didn't want in the main config files.

    -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??? *

Tags for this Thread

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