Double Close!

Posts 1–15 of 18 · Page 1 of 2
Double Close!
Hey

I'm trying to write an array containing file directories to a text document. When i try this code on form close it writes to the file, but i have to hit close twice most of the time :\ Could anyone explain why?

Code:
        Dim w As New StreamWriter("C:\IMtemp\dlls.txt")
        For Each IDLL In dlls
            If counter3 < ListBox1.Items.Count Then
                w.WriteLine(IDLL)
                counter3 = counter3 + 1
            End If
        Next
        w.Close()
because if there is any error example no size or no rights
it is to make sure that ur text is written correctly
[highlight=vb.net]
IO.File.WriteAllLines("C:\IMtemp\dlls.txt", dlls.Items.Cast(Of Object).Select(Function(i As Object) i.ToString()).ToArray())
[/highlight]

And try it on the Form_closed event and make sure to set e.Cancel = false as well just in case.
Quote Originally Posted by Jason View Post
[highlight=vb.net]
IO.File.WriteAllLines("C:\IMtemp\dlls.txt", dlls.Items.Cast(Of Object).Select(Function(i As Object) i.ToString()).ToArray())
[/highlight]

And try it on the Form_closed event and make sure to set e.Cancel = false as well just in case.
Thanks, i'll try it when i get home.

WHat is e.Cancel btw? It gives me a error in my code :\
Quote Originally Posted by Codemunkie View Post
Thanks, i'll try it when i get home.

WHat is e.Cancel btw? It gives me a error in my code :\
Code:
Private Sub FormClosed(sender As System.Object, e As FormClosedEventsArg) Handles MyBase.FormClosed
        'Code
End Sub
Wait, where are you putting that code :/
Quote Originally Posted by Jason View Post
Wait, where are you putting that code :/
Its going in form1_formclosed
Quote Originally Posted by Codemunkie View Post
Its going in form1_formclosed
change the event to form closing
Quote Originally Posted by T0P-CENT View Post
change the event to form closing
Nvm ;P
Quote Originally Posted by T0P-CENT View Post
change the event to form closing
Doesn't change anything I still have to close the form twice.
Quote Originally Posted by Codemunkie View Post
Doesn't change anything I still have to close the form twice.
Just put an End at the bottom then . It's messy as fuck but it should work anyway.
Quote Originally Posted by wtfiwantthatname View Post
me.close()?
Well seeing as this event is firing on the form close event, telling it close itself again probably won't help.
me.close weirdly crashes my application and End doesn't change anything

Nevermind anyway, i'm using a button to save the file now.
Quick Question. Does your program write everything to the file correctly?
Posts 1–15 of 18 · Page 1 of 2

Post a Reply

Tags for this Thread

None

Need help?