Results 1 to 8 of 8

Thread: [RESOLVED] My.Settings not saving.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [RESOLVED] My.Settings not saving.

    I'm new to the .NET way of VB...

    I've setup some simple settings for a program i'm creating.

    The settings pretty much just save the forms Left & Top positions.

    After i setup the settings, i changed the "Root Namespace" and "Assembly Name".

    Now, for some reason, when ever i save to my.settings, it won't save once the program has been closed. I've checked the "app.config" file and it seems to be all good.

    Any way, checkout these screen shots: You may notice that the settings are strings in the app.config file, but in the project's properties they are integers. I originally set them as integers. I don't know why strings were put there.




  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: My.Settings not saving.

    Dont worry about the serializeAs="String" tag, thats just the way it always "does".

    If you want the location of the form to be set from the settings at startup and saved to the settings at shutdown, theres a simple way:
    Create a setting of type System.Drawing.Point.
    In the form properties, select (ApplicationSettings) and then (PropertyBinding).
    In the dialog that appears, choose the Location property and select the newly created setting in the dropdownlist.

    The forms Location property is now bound to the setting
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: My.Settings not saving.

    Oh, the forms position isn't the problem. That could be easily fixed.

    But why doesn't the my.settings work?

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

    Re: My.Settings not saving.

    Please provide a list of steps that we can perform to reproduce the issue, starting with a new project.
    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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: My.Settings not saving.

    Umm, i've tried to replicate the problem... but have failed. Though this is not the first time it has happened and it's a completely new program i had started to make.

    Any way, i've uploaded the project, perhaps you could find out why it's doing it, how to fix, or how to prevent.

    http://www.megafileupload.com/en/fil...Timer-rar.html

    In the mean time, i'm just going to start the program again and copy what i have already started. But i would still like to know how to fix this problem instead of running from it. Also on a side note, this problem has happened before, on one particular program i was making it would save Integer values, but it wouldn't save Strings. I had all the variable types set properly and that too.

    Thank you =).
    Last edited by Slyke; Jan 27th, 2008 at 09:10 AM.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: My.Settings not saving.

    OK, I got it to replicate the error, twice now:

    This is what i did:

    1. Create a new project
    2. Copy all the controls from the old project (Using Ctrl+A, Ctrl+C)
    3. Pasted All the controls (Ctrl+V)
    4. Resized the form to fit the controls.
    5. Changed the Form's MaximizeBox Property to False
    6. Changed the Form's FormBorderStyle to FixedSingle
    7. Renamed the form to "FrmMain"
    8. Changed the forms filename to "FrmMain" (In Visual Basic of course).
    9. Changed the Root Namespace and Assembly name to "Shutdown".
    10. Went into settings and put in FrmMainX and FrmMainY and made them both as integers.
    11. Pasted the following code into the form:
    vb Code:
    1. Private Sub CmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdExit.Click
    2.  
    3.         My.Settings.FrmMainX = Me.Left
    4.         My.Settings.FrmMainY = Me.Top
    5.  
    6.         Dim I As Integer
    7.  
    8.         For I = 1000 To 1 Step -1
    9.  
    10.             Me.Opacity = I / 100
    11.  
    12.             Application.DoEvents()
    13.  
    14.         Next
    15.  
    16.         Me.Opacity = 0
    17.  
    18.         Me.Hide()
    19.         End
    20.  
    21.     End Sub
    22.  
    23.  
    24.     Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    25.  
    26.         CmdExit_Click(CmdExit, e)
    27.  
    28.     End Sub
    29.  
    30.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    31.  
    32.         Me.Left = My.Settings.FrmMainX
    33.         Me.Top = My.Settings.FrmMainY
    34.  
    35.     End Sub

    12. Started it and closed the form, started it again and it was back at the default position.

    By the way, It didn't matter if the Form1_Load and Form1_FormClosed subs were named FrmMain_Load and FrmMain_FormClosed. It still happens
    Last edited by Slyke; Jan 27th, 2008 at 09:28 AM.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: My.Settings not saving.

    Adding in My.Settings.Save seems to fix this problem.

    But it saves without My.Settings.Save Sometimes too! If no one has anything to say to this I'll mark the thread resolved.

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

    Re: [RESOLVED] My.Settings not saving.

    Have you set the StartPosition property of the form to Manual? If not then manually setting the Location will have no effect as the form will be shown initially where the StartPosition property tells it to be.
    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