0

The issue I'm having is that my settings don't seem to save when the project has ended.

My project consists of a FrmMain, and FrmSettings

Code is as follows:

FrmMain: The settings should load when the main form loads

    Private Sub FrmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '//Load Settings\\
        My.Settings.Reload()
        FrmSettings.settingsTXTsearch.Text = My.Settings.SettingSearchTerm
        '\\Load Settings//
    End Sub

FrmSettings:

Private Sub SettingsButtonApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsButtonApply.Click
    My.Settings.SettingSearchTerm = settingsTXTsearch.Text
End Sub

I've also added a button that shows me what My.Settings.SettingsSearchTerm's value is, and it is being stored correctly, but once the project ends, the value is not saved. (Using me.close() and END)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    MsgBox(My.Settings.SettingSearchTerm)
End Sub

Please let me know if you need any more information from me, or code samples.

level42
  • 946
  • 2
  • 13
  • 33
  • Note: Save My.Settings on Shutdown is already enabled under Application. – level42 Jun 16 '14 at 20:32
  • 2
    My guess is that your use of [`End`](http://msdn.microsoft.com/en-us/library/0wt87xba.aspx) is causing the settings to not be saved, since it terminates the application abruptly. Just using `Me.Close()` on the main form should terminate the application, so try removing the `End` call and see if that helps. – Mark Jun 16 '14 at 21:17
  • Are they application settings or user settings? – Steve Jun 16 '14 at 22:42
  • 2
    As Mark said, get rid of the `End`. It should never be used in VB.NET, whether it's the cause of your issue or not. Calling `Close` on the startup form or last form will exit the app, depending on your project configuration, or you can call `Application.Exit` anywhere, any time. I liken `End` to a bouncer in a night club grabbing someone by the scruff of the neck and throwing them out while they spill their drink on others nearby as they kick and scream while the other options are asking the patron to leave so they can finish their drink, put down their glass and walk out quietly. – jmcilhinney Jun 17 '14 at 01:10
  • That seem's to have done the trick guys, thanks for the comments! – level42 Jun 17 '14 at 14:04

1 Answers1

0

Removing the END command from the form closing event seems to have resolved the issues. Thanks to the comments in the original post.

Code Removed:

Private Sub Main_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Me.Close()
    End
End Sub
level42
  • 946
  • 2
  • 13
  • 33