none
Can't Make my Setting Persist RRS feed

  • Question

  • I want to save my setting of a path  to the folder to store test data. The user can select the folder. I can save the name OK but it doesn't save it in my settings. So when I start the program again in still has the old setting. I have read all the info but see nothing that gives me the code to change the setting when I quit the program. This is the code I have.

     Try
                MsgBox("This will Select the Folder To Save Test Results. It should be a folder you have access to such as C:\WBLGTestData When you save data the file name will be the Test No shown on the Main Screen", vbOKCancel, "Test Data Folder")
                FolderBrowserDialog1.ShowDialog()
                TestFolder = FolderBrowserDialog1.SelectedPath
                My.Settings.TestF = TestFolder
                If MsgBox("Do You Want To use this folder " + TestFolder + " ?", vbYesNo) = MsgBoxResult.Yes Then
                    My.Settings.Save()
               
                    MsgBox("Folder Saved", vbOKOnly, "")
                Else
                    MsgBox("Canceled", vbOKOnly, "")
                End If
                Exit Sub

    I have scope set to User and Roaming set to True. Using VB 2015

            Please Help!                                                                                                                                                                                                                                

    • Edited by Bedford Bob Friday, September 8, 2017 2:52 AM
    Friday, September 8, 2017 2:36 AM

Answers

  • I can save the name OK but it doesn't save it in my settings. So when I start the program again in still has the old setting.

    Your settings are saved automatically when the application terminates.   So if there is some code somewhere that is setting TestF back to the value it had at application start, then that will overwrite the change you made in the above code.  

    You should insert a breakpoint at the form closing event, check the My.Settings.TestF value at that point, then single step through the code to see if the settings value is being changed before it gets saved again.

    • Marked as answer by Bedford Bob Friday, September 8, 2017 6:22 PM
    Friday, September 8, 2017 3:45 AM

All replies

  • I can save the name OK but it doesn't save it in my settings. So when I start the program again in still has the old setting.

    Your settings are saved automatically when the application terminates.   So if there is some code somewhere that is setting TestF back to the value it had at application start, then that will overwrite the change you made in the above code.  

    You should insert a breakpoint at the form closing event, check the My.Settings.TestF value at that point, then single step through the code to see if the settings value is being changed before it gets saved again.

    • Marked as answer by Bedford Bob Friday, September 8, 2017 6:22 PM
    Friday, September 8, 2017 3:45 AM
  • Thank you so much! I fought that thing for a couple of hours. I usually save an ini file with this kind of information but settings seemed so much more easy I wanted to use them. I was sure that I just did not understand it so didn't look for redefining it. I do feel stupid but I fixed it thanks to your help. That's great.
    Friday, September 8, 2017 6:26 PM