-1

Windows 10 64-bit, VB.NET 2017

I have a textbox and I want to persist its value. I type in 20, and usually it persists next time I start program. But sometimes it's blank. Nothing in code changes it. I am debugging another part of code. Sometimes I single-step and edit code. Sometimes I do shift-F5 to end the program. Usually the 20 persists.

In project > props > Settings it is a user variable, string, named: TextBox_OD_log10_gain (same name as the textbox that it sets)

HERE IS WHERE TEXTBOX IS LOADED AT BOOT-TIME.............

Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    application.DoEvents
    TextBox_OD_log10_gain.text = my.settings.TextBox_OD_log10_gain
End Sub

HERE IS ONLY PLACE THAT TEXTBOX IS SET...............

Private Sub MainForm_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
                my.settings.TextBox_OD_log10_gain = TextBox_OD_log10_gain.text 
        My.Settings.Save()
End Sub

' Alessandro Mandelli' below suggests that problem is a malfunction with .NET Framework. Is this true?? Should I just give up on my.settings. and use a different method?

Doug Null
  • 7,989
  • 15
  • 69
  • 148

2 Answers2

0

It's possible that when you press Shift+F5 to terminate your debugging session, you are immediately ending the program at where it's currently executing and it never gets the chance to fire or process the FormClosed event, which in turn means your settings never get saved. You should probably close the form itself when you are finished debugging so it has a chance to execute any additional saving or cleanup you have specified, instead of ending it abruptly from outside the code.

Knowledge Cube
  • 990
  • 12
  • 35
  • That wouldn't cause it to come up blank, the last saved setting would still be there, and if it's 20 and he doesn't change it, it should stay 20. But that would be easy to check, with a breakpoint or something. – Patrick Aug 31 '17 at 23:03
  • Same environment as you, same issue. Intermittent failure to either load or save settings. It appears to be a bug of some sort, either on the .net framework or its interaction with w10/64. I suspect a xml corruption in one of the files in Reference Assemblies folder – Alessandro Mandelli Sep 01 '17 at 06:30
  • CKH: I verified that wasn't the problem. – Doug Null Sep 07 '17 at 15:38
-1

I'm giving up on my.Settings. Too unreliable. No decent examples or doc. Some of my settings stick, others do not.

My answer is to go back to "GetSetting" which I never had a problem with. Also, GetSetting takes about half the time to code.

Doug Null
  • 7,989
  • 15
  • 69
  • 148