Spyru Posted October 8, 2003 Posted October 8, 2003 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 Quote
Administrators PlausiblyDamp Posted October 8, 2003 Administrators Posted October 8, 2003 If you step through the code in the debugger what line of code does it throw the error on? The error means you are trying to reference an object that is set to nothing - could you post some of the relevant code? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Spyru Posted October 8, 2003 Author Posted October 8, 2003 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 Quote
Administrators PlausiblyDamp Posted October 9, 2003 Administrators Posted October 9, 2003 Can't see anything really wrong there - nothing that I would expect to give a NullReferenceException anyway. If you step through the code - what line does it fail on? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Spyru Posted October 12, 2003 Author Posted October 12, 2003 It fails on End... After End, it gives the Windows error, and then the VB error. No more errors :S grtz, Spyru Quote
Administrators PlausiblyDamp Posted October 12, 2003 Administrators Posted October 12, 2003 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Engine252 Posted October 13, 2003 Posted October 13, 2003 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 Quote
AndreRyan Posted October 14, 2003 Posted October 14, 2003 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 Quote .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?
Administrators PlausiblyDamp Posted October 14, 2003 Administrators Posted October 14, 2003 If you remove the end statement does the program close anyway? If not look for places in your code where you are opening other forms and ensure that they are also closed when finished with. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Spyru Posted October 16, 2003 Author Posted October 16, 2003 I think I fixed it, I placed Form1.ActiveForm.Close() before it. I think this is it! :D grtz&thx Spyru Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.