Results 1 to 5 of 5

Thread: My.Settings

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    313

    My.Settings

    I'm having trouble understanding how this works.Under my Project properties I select Settings and define the ones I need.Things like:

    DefaultSaveToLocation (As String)
    DefaultFileName (As String)
    NoOfTimesAppStarted (As Integer)
    and so on....

    Under Form_Load I check to see if NoOfTimesAppStarted is 1.If so,display some configuration options,close the DialogBox and show Form1.Also,increase NoOfTimesAppStarted + 1.
    Then My.Settings.Save().
    This works,as the next time I start it,it skips the DialogBox and goes straigth to Form1.But under Settings,the value of NoOfTimesAppStarted is still 1.

    Also,I can't seem to set the ApplicationPath.I use AppPath =My.Application.Info.DirectoryPath to get the path and save it to My.Settings.DefaultSaveToLocation,but no deal!

    vb.net Code:
    1. AppPath = My.Application.Info.DirectoryPath
    2. My.Settings.DefaultSaveToLocation = AppPath
    3.             My.Settings.Save()

    What am I doing wrong?

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

    Re: My.Settings

    you're not doing anything wrong per se... but when you look at it from the project settings, what you are seeing is the default settings... basically what is in the app.settings file in your project. At run-time though it will will first read in the yourapp.exe.config... then it will look for the user copy of the config file... and overlay the two, with the user settings file taking precidence over the app one. The merged result is what becomes your settings as you are trying to read it.

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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    313

    Re: My.Settings

    I see what you mean.I just placed MessageBox.Show(My.Settings.DefaultSaveLocation) and it displayed it for me,although it doesn't appear under Settings.
    Also,I read that it's good to use the PropertyGrid control to display the settings,but I can't find it anywhere?!
    Last edited by BlackRiver; Apr 5th, 2010 at 02:40 PM.

  4. #4
    Addicted Member
    Join Date
    Oct 2009
    Location
    Clive, IA in America!!!!
    Posts
    204

    Re: My.Settings

    Another question: where are these settings stored? I searched the registry, but I didn't find anything... and no file was created by the executable.

    VBNetDude - Thinking Programmatically
    By Silver Seal Software

    Don't forget to mark your thread as "Resolved" using the Thread Tools menu on top. And don't forget to rate the answers that help you the most!

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

    Re: My.Settings

    in the bin\Debug folder you should find a file with_your_app_name.exe.config ... that will hold the application scope settings & default values for user scoped settings. Then there is a user scoped config file that gets stored in your profile.

    Some useful links:
    http://www.vbforums.com/showthread.p...ettings+stored
    http://www.vbforums.com/showthread.p...ettings+stored
    http://msdn.microsoft.com/en-us/magazine/cc163812.aspx

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

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