Private Sub MainForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If My.Settings.My_First_Build = True Then
            If OptionsForm.AutoSaveallOnExitCKB.CheckState = CheckState.Checked Then
                If Tab4RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem1_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                    MessageBox.Show("Not modified")
                End If
                If Tab5RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem2_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                End If
                If Tab6RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem3_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                End If
                If Tab7RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem4_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                End If
            Else
            End If
        Else
            ' : My.Settings.My_First_Build = False
            If OptionsForm.AutoSaveallOnExitCKB.CheckState = CheckState.Checked Then
                'Try
                Tab4RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage4_LastFile)
                Tab5RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage5_LastFile)
                Tab6RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage6_LastFile)
                Tab7RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage7_LastFile)
                If moonopentext.FileName = Nothing Then
                Else
                    NotesViewerRichTextBoxCtrl.SaveFile(currentFile, RichTextBoxStreamType.PlainText)
                End If
                My.Settings.My_OpeniconLocation_Loco = OptionsForm.CustmIcon.FileName
                My.Settings.Save()
                '      '
                '  End Try
            Else
            End If
        End If
    End Sub

WHY Wont it save if build true or false none works:(

Could you please elaborate on the actual issue and the faulty line(s) of code as I'm currently having a hard time understanding what you would like to achieve. Thank you.

I would like to Do the following
If its the first run of thee App
Then at form closing it should see if some of the richtextboxs were modified at then it show a save dialog for each of the 4 richtextboxs in sequence of course then save those files to a location and then if its not the First run it should save the modified richtextboxs to the files tht were saved on App First run as yu can see above
but for some reason it doesnt work...

From what i see the problem seems to be:
If OptionsForm.AutoSaveallOnExitCKB.CheckState

I assume the OptionsForm is a Form, that is not initialized at that time. So the CheckBox AutoSaveallOnExitCKB is also not initialized.

I would suggest to save the option "SaveOnClose" also in your My.Settings and check its value instead.

Im not really sure what you are saying..
New code Made a few Steps Forward But
- If OptionsForm.AutoSaveallOnExitCKB.CheckState = CheckState.Checked Then
still doesnt work Strange i got it working when i started the project:'(
Anyway Here Latest Code :

Private Sub MainForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If My.Settings.My_First_Build = True Then
            If OptionsForm.AutoSaveallOnExitCKB.CheckState = CheckState.Checked Then
                If Tab4RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem1_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                    MessageBox.Show("Not modified")
                End If
                If Tab5RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem2_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                End If
                If Tab6RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem3_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                End If
                If Tab7RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem4_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                End If
            Else
            End If
        Else
            ' : My.Settings.My_First_Build = False
            If OptionsForm.AutoSaveallOnExitCKB.CheckState = CheckState.Checked Then
                Try
                    Tab4RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage4_LastFile, RichTextBoxStreamType.PlainText)
                    Tab5RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage5_LastFile, RichTextBoxStreamType.PlainText)
                    Tab6RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage6_LastFile, RichTextBoxStreamType.PlainText)
                    Tab7RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage7_LastFile, RichTextBoxStreamType.PlainText)
                    If moonopentext.FileName = Nothing Then
                    Else
                        NotesViewerRichTextBoxCtrl.SaveFile(currentFile, RichTextBoxStreamType.PlainText)
                    End If
                    My.Settings.My_OpeniconLocation_Loco = OptionsForm.CustmIcon.FileName
                    My.Settings.Save()
                Catch Err As Exception
                    If My.Settings.My_TabPage4_LastFile & My.Settings.My_TabPage5_LastFile & My.Settings.My_TabPage6_LastFile & My.Settings.My_TabPage7_LastFile = Nothing Then
                        If Tab4RichTextBoxPrintCtrl.Modified = True Then
                            SaveAsMenuItem1_Click(Me, e)
                            Threading.Thread.Sleep(100)
                        Else
                            MessageBox.Show("Not modified")
                        End If
                        If Tab5RichTextBoxPrintCtrl.Modified = True Then
                            SaveAsMenuItem2_Click(Me, e)
                            Threading.Thread.Sleep(100)
                        Else
                        End If
                        If Tab6RichTextBoxPrintCtrl.Modified = True Then
                            SaveAsMenuItem3_Click(Me, e)
                            Threading.Thread.Sleep(100)
                        Else
                        End If
                        If Tab7RichTextBoxPrintCtrl.Modified = True Then
                            SaveAsMenuItem4_Click(Me, e)
                            Threading.Thread.Sleep(100)
                        Else
                        End If
                    Else
                    End If
                End Try
            Else
            End If
        End If
    End Sub

OptionsForm.AutoSaveallOnExitCKB.CheckState will never be CheckState.Checked (except this checkbox is set to checked by default.

OptionsForm is not initialized, so this checkbox will ALWAYS have its initial value (by default unchecked).

What i were suggesting is to save the current AutoSaveallOnExitCKB.CheckState in your My.Setting when closing the OptionsForm.

Then you only need to check If My.Settings.SaveOnExit Then ....

I think I got it working My old One line of code i used now
SO LATEST Code is :

Private Sub MainForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        OptionsForm.AutoSaveallOnExitCKB.Checked = My.Settings.My_Save_On_Exit
        If My.Settings.My_First_Build = True Then
            If OptionsForm.AutoSaveallOnExitCKB.CheckState = CheckState.Checked Then
                If Tab4RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem1_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                    MessageBox.Show("Not modified")
                End If
                If Tab5RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem2_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                End If
                If Tab6RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem3_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                End If
                If Tab7RichTextBoxPrintCtrl.Modified = True Then
                    SaveAsMenuItem4_Click(Me, e)
                    Threading.Thread.Sleep(100)
                Else
                End If
            Else
            End If
        ElseIf My.Settings.My_First_Build = False Then
            If OptionsForm.AutoSaveallOnExitCKB.CheckState = CheckState.Checked Then
                Try
                    Tab4RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage4_LastFile, RichTextBoxStreamType.PlainText)
                    Tab5RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage5_LastFile, RichTextBoxStreamType.PlainText)
                    Tab6RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage6_LastFile, RichTextBoxStreamType.PlainText)
                    Tab7RichTextBoxPrintCtrl.SaveFile(My.Settings.My_TabPage7_LastFile, RichTextBoxStreamType.PlainText)
                    If moonopentext.FileName = Nothing Then
                    Else
                        NotesViewerRichTextBoxCtrl.SaveFile(currentFile, RichTextBoxStreamType.PlainText)
                    End If
                    My.Settings.My_OpeniconLocation_Loco = OptionsForm.CustmIcon.FileName
                    My.Settings.Save()
                Catch Err As Exception
                    If My.Settings.My_TabPage4_LastFile & My.Settings.My_TabPage5_LastFile & My.Settings.My_TabPage6_LastFile & My.Settings.My_TabPage7_LastFile = Nothing Then
                        If Tab4RichTextBoxPrintCtrl.Modified = True Then
                            SaveAsMenuItem1_Click(Me, e)
                            Threading.Thread.Sleep(100)
                        Else
                            MessageBox.Show("Not modified")
                        End If
                        If Tab5RichTextBoxPrintCtrl.Modified = True Then
                            SaveAsMenuItem2_Click(Me, e)
                            Threading.Thread.Sleep(100)
                        Else
                        End If
                        If Tab6RichTextBoxPrintCtrl.Modified = True Then
                            SaveAsMenuItem3_Click(Me, e)
                            Threading.Thread.Sleep(100)
                        Else
                        End If
                        If Tab7RichTextBoxPrintCtrl.Modified = True Then
                            SaveAsMenuItem4_Click(Me, e)
                            Threading.Thread.Sleep(100)
                        Else
                        End If
                    Else
                    End If
                End Try
            Else
            End If
        End If
    End Sub

:P But anyway Thanks Geek Ill still hold it open if it Seems not to work in near Future;)

why dont you just use:

If My.Settings.My_Save_On_Exit = True Then
...

instead of

OptionsForm.AutoSaveallOnExitCKB.Checked = My.Settings.My_Save_On_Exit
If OptionsForm.AutoSaveallOnExitCKB.CheckState = CheckState.Checked Then
...

Edited 5 Years Ago by GeekByChoiCe: n/a

This article has been dead for over six months. Start a new discussion instead.