Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I've made a program, with an OpenDialog and a SaveDialog in it. When I have NOT used any of these when running it, it wil quit FINE. But when I've used one or both of 'em, my program gives an error when quiting.

 

These are the errors: :(

 

Error Windows gave:

http://members.lycos.nl/spyru/dotnetforums/weirderror/winerror.jpg

 

Error VS gave:

http://members.lycos.nl/spyru/dotnetforums/weirderror/vberror.jpg

 

grtz and thx, Spyru :D

Posted

OK, here is some code: :p

 

This is where the OpenDialog (ofdOpenen) executes:

   Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
       ofdOpenen.ShowDialog()
       Dim sLine As String
       Dim nIndexLine As Integer
       If Not ofdOpenen.FileName = "" Then
           lviclear()
           FileSystem.FileOpen(1, ofdOpenen.FileName, OpenMode.Input)
           Do
               sLine = FileSystem.LineInput(1)
               nIndexLine = sLine.IndexOf("�")
               ListView1.Items.Add(sLine.Substring(0, nIndexLine))
               ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(sLine.Substring(nIndexLine + 1, sLine.Length - nIndexLine - 1))
           Loop Until EOF(1)
           FileSystem.FileClose(1)
           bWijzSaved = True
       End If
   End Sub

 

This is where I save the file:

   Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
       Opslaan("Save")
   End Sub

   Private Sub Opslaan(ByVal sType As String)
       If sType = "Save" Then
           If bHeeftFile = True Then
               Save()
           Else
               sfdOpslaan.ShowDialog()
               If Not sfdOpslaan.FileName = "" Then
                   Save()
                   bWijzSaved = True
                   bHeeftFile = True
               End If
           End If
       Else
           sfdOpslaan.ShowDialog()
           If Not sfdOpslaan.FileName = "" Then
               Save()
               bWijzSaved = True
               bHeeftFile = True
           End If
       End If
   End Sub
   Public Sub Save()
       Dim i As Integer
       FileSystem.FileOpen(1, sfdOpslaan.FileName, OpenMode.Output)
       For i = 1 To ListView1.Items.Count - 1
           FileSystem.PrintLine(1, ListView1.Items(i).Text + "�" + ListView1.Items(i).SubItems(1).Text)
       Next
       FileSystem.FileClose(1)
   End Sub

   Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
       Opslaan("SaveAs")
   End Sub

 

This is where I check if closing the file is OK (changes saved and stuff):

 

   Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click
       If CheckClose() = "Yes" Then End
   End Sub

   Private Function CheckClose() As String
       Dim h As Integer
       If bWijzSaved Then
           Return "Yes"
       Else
           h = MsgBox("Weet u zeker dat u wilt afsluiten?" + vbCrLf + "Er zijn nog onopgeslagen wijzigingen aanwezig.", MsgBoxStyle.Question Or MsgBoxStyle.YesNo)
           If h = MsgBoxResult.Yes Then Return "Yes"
           If h = MsgBoxResult.No Then Return "No"
       End If
   End Function

   Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
       e.Cancel = False
       If CheckClose() = "Yes" Then End
   End Sub

 

It's pretty much, but I thank you if you would be able to solve this damned error :P

 

grtz&thx Spyru

  • Administrators
Posted

Is this the only form in the project? If so try letting the form close itself without calling End. If not make sure all the other forms are closed and then allow the main form to just exit normally.

 

End is known to cause problems and is generally considered a bad way to terminate a program - search the forums and you'll find many people suggesting better ways.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

try this in your Closing sub

 

 

 

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

Try

If CheckClose() = "Yes" Then

End

else

e.cancel = true

end if

Catch ex As Exception

 

End Try

End Sub

Posted
It was just said that this is a bad way to terminate the program:
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Try
If CheckClose() = "Yes" Then 
   End 'Do not use this command ever
Else
   e.cancel = true
End If
Catch ex As Exception

End Try 
End Sub

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...