Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

I need a StreamWriter in a .Net Windows Application available to all forms.

Avatar of AndrewMagruder
AndrewMagruder asked on
.NET ProgrammingVisual Basic.NET
4 Comments1 Solution252 ViewsLast Modified:
I want to open a new text file for writing when my VB .NET 2005 Windows application starts and have all Forms in the application able to write to it.  I want the file to close when the ap closes. i've tried code in MAIN and MyApplication Startup event handler but the streamwriter is nothing in the forms.
Imports Microsoft.VisualBasic.ApplicationServices
Imports System.IO
 
 
Namespace My
 
    ' The following events are availble for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication
 
 
        Public Debug_Flow_WRITE As StreamWriter
        Public Property Debug_Flow_SR() As StreamWriter
            Get
                Return Debug_Flow_WRITE
            End Get
            Set(ByVal value As StreamWriter)
                Debug_Flow_WRITE = value
            End Set
        End Property
 
 
        Public Sub Me_Startup( _
        ByVal sender As Object, _
        ByVal e As StartupEventArgs _
        ) Handles Me.Startup
 
            File.Delete("C:\Program Files\KVH Industries Inc\M10_Scan 1.1\M10_Scan_Trace.txt")
            Debug_Flow_WRITE = File.CreateText("C:\Program Files\KVH Industries Inc\M10_Scan 1.1\M10_Scan_Trace.txt")
 
        End Sub
 
        Public Sub Me_ShutDown( _
        ByVal sender As Object, _
        ByVal e As EventArgs _
        ) Handles Me.Shutdown
 
            Debug_Flow_WRITE.Close()
 
        End Sub
 
 
    End Class
 
End Namespace
 
 
 
        ' This code is in a form
        ' Debug_Flow_WRITE is nothing
        ' My.Application.Debug_Flow_SR is nothing too
        My.Application.Debug_Flow_WRITE.WriteLine("Leaving txtKVHSerialNumber.KeyUp at End Sub.")
ASKER CERTIFIED SOLUTION
Avatar of VBRocks
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers