Hi all.
I have a Sub that calls another sub. Both subs use a common object, so I
used Public to declare it at the top of the module, as below.
Public Writer As StreamWriter = File.CreateText (Application.St artupPath &
"\Update.tx t")
The first time my Sub runs it works fine. But the second time it fails
telling me "Cannot write to a closed TextWriter. I am guessing that this is
because the Public section is only read once instance of the application. I
have to close the TextWriter so that I can use the file in another process.
Any idea how I can either ensure that the Public section is re-read, or,
provide the TextWriter to the 2nd Sub?
--
Bob Hollness
-------------------------------------
I'll have a B please Bob 10 2158
I think I'm a little confused at what you need to do. But your problem lies
in
If you declare like this:
Public Writer As StreamWriter
Public Sub1()
if Writer is Nothing then
Wrier = File.CreateText (Application.St artupPath & "\Update.tx t")
end if
'Do Something
End Sub
Public Sub2()
if Writer is Nothing then
Wrier = File.CreateText (Application.St artupPath & "\Update.tx t")
end if
'Do Something
End Sub
Public Sub DoSomethingThat MustCloseFile
Writer.Close
Writer = Nothing
End Sub
Now this way of doing it opens the file if it was closed. And uses the same
file if it was already opened. I think this is what you are talking about
doing. If not, can you post some sample code that shows the problem more?
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message
news:Ok******** ******@TK2MSFTN GP14.phx.gbl... Hi all.
I have a Sub that calls another sub. Both subs use a common object, so I used Public to declare it at the top of the module, as below.
Public Writer As StreamWriter = File.CreateText (Application.St artupPath & "\Update.tx t")
The first time my Sub runs it works fine. But the second time it fails telling me "Cannot write to a closed TextWriter. I am guessing that this is because the Public section is only read once instance of the application. I have to close the TextWriter so that I can use the file in another process. Any idea how I can either ensure that the Public section is re-read, or, provide the TextWriter to the 2nd Sub?
-- Bob Hollness
------------------------------------- I'll have a B please Bob
I think I'm a little confused at what you need to do. But your problem lies
in
If you declare like this:
Public Writer As StreamWriter
Public Sub1()
if Writer is Nothing then
Wrier = File.CreateText (Application.St artupPath & "\Update.tx t")
end if
'Do Something
End Sub
Public Sub2()
if Writer is Nothing then
Wrier = File.CreateText (Application.St artupPath & "\Update.tx t")
end if
'Do Something
End Sub
Public Sub DoSomethingThat MustCloseFile
Writer.Close
Writer = Nothing
End Sub
Now this way of doing it opens the file if it was closed. And uses the same
file if it was already opened. I think this is what you are talking about
doing. If not, can you post some sample code that shows the problem more?
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message
news:Ok******** ******@TK2MSFTN GP14.phx.gbl... Hi all.
I have a Sub that calls another sub. Both subs use a common object, so I used Public to declare it at the top of the module, as below.
Public Writer As StreamWriter = File.CreateText (Application.St artupPath & "\Update.tx t")
The first time my Sub runs it works fine. But the second time it fails telling me "Cannot write to a closed TextWriter. I am guessing that this is because the Public section is only read once instance of the application. I have to close the TextWriter so that I can use the file in another process. Any idea how I can either ensure that the Public section is re-read, or, provide the TextWriter to the 2nd Sub?
-- Bob Hollness
------------------------------------- I'll have a B please Bob
Thanks for the reply. This is my code. As you can see, it recurses by
calling itself repeatedly. And then the sub ReadAllFiles tidies up by
closing the stream. My problem is that the 2nd time it runs it errors on
line ".WriteLine(sFi le) in the ReadDirs Sub.
Sub ReadAllFiles
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush
WriteTxtUpdate. Close
End Sub
Sub ReadDirs(ByVal Sourcedir As String, ByVal recursive As Boolean)
Sourcedir &= Path.DirectoryS eparatorChar
If fRecursive Then
For Each sDir In Directory.GetDi rectories(Sourc edir)
sDirInfo = New DirectoryInfo(s Dir)
ReadDirs(sDirIn fo.FullName, fRecursive)
sDirInfo = Nothing
Next
End If
With WriteTxtUpdate
For Each sFile In Directory.GetFi les(Sourcedir)
.WriteLine(sFil e)
Next
End With
End Sub
--
Bob Hollness
-------------------------------------
I'll have a B please Bob
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote
in message news:e0******** *****@TK2MSFTNG P12.phx.gbl... I think I'm a little confused at what you need to do. But your problem lies in
If you declare like this:
Public Writer As StreamWriter
Public Sub1() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub2() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub DoSomethingThat MustCloseFile Writer.Close Writer = Nothing End Sub
Now this way of doing it opens the file if it was closed. And uses the same file if it was already opened. I think this is what you are talking about doing. If not, can you post some sample code that shows the problem more?
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message news:Ok******** ******@TK2MSFTN GP14.phx.gbl... Hi all.
I have a Sub that calls another sub. Both subs use a common object, so I used Public to declare it at the top of the module, as below.
Public Writer As StreamWriter = File.CreateText (Application.St artupPath & "\Update.tx t")
The first time my Sub runs it works fine. But the second time it fails telling me "Cannot write to a closed TextWriter. I am guessing that this is because the Public section is only read once instance of the application. I have to close the TextWriter so that I can use the file in another process. Any idea how I can either ensure that the Public section is re-read, or, provide the TextWriter to the 2nd Sub?
-- Bob Hollness
------------------------------------- I'll have a B please Bob
Thanks for the reply. This is my code. As you can see, it recurses by
calling itself repeatedly. And then the sub ReadAllFiles tidies up by
closing the stream. My problem is that the 2nd time it runs it errors on
line ".WriteLine(sFi le) in the ReadDirs Sub.
Sub ReadAllFiles
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush
WriteTxtUpdate. Close
End Sub
Sub ReadDirs(ByVal Sourcedir As String, ByVal recursive As Boolean)
Sourcedir &= Path.DirectoryS eparatorChar
If fRecursive Then
For Each sDir In Directory.GetDi rectories(Sourc edir)
sDirInfo = New DirectoryInfo(s Dir)
ReadDirs(sDirIn fo.FullName, fRecursive)
sDirInfo = Nothing
Next
End If
With WriteTxtUpdate
For Each sFile In Directory.GetFi les(Sourcedir)
.WriteLine(sFil e)
Next
End With
End Sub
--
Bob Hollness
-------------------------------------
I'll have a B please Bob
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote
in message news:e0******** *****@TK2MSFTNG P12.phx.gbl... I think I'm a little confused at what you need to do. But your problem lies in
If you declare like this:
Public Writer As StreamWriter
Public Sub1() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub2() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub DoSomethingThat MustCloseFile Writer.Close Writer = Nothing End Sub
Now this way of doing it opens the file if it was closed. And uses the same file if it was already opened. I think this is what you are talking about doing. If not, can you post some sample code that shows the problem more?
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message news:Ok******** ******@TK2MSFTN GP14.phx.gbl... Hi all.
I have a Sub that calls another sub. Both subs use a common object, so I used Public to declare it at the top of the module, as below.
Public Writer As StreamWriter = File.CreateText (Application.St artupPath & "\Update.tx t")
The first time my Sub runs it works fine. But the second time it fails telling me "Cannot write to a closed TextWriter. I am guessing that this is because the Public section is only read once instance of the application. I have to close the TextWriter so that I can use the file in another process. Any idea how I can either ensure that the Public section is re-read, or, provide the TextWriter to the 2nd Sub?
-- Bob Hollness
------------------------------------- I'll have a B please Bob
You are talking about "2nd time" meaning the second time you call the
function ReadAllFiles right. If that is the case then my solution in my
previous post solves the problem. After you close WriteTextUpdate you have
to open it again before you use it. Two ways to solve it.
1. Declare WriteTextUpdate inside ReadAllFiles and pass it into ReadDirs
2. (Probably a better way for this case, as I stated before) Define then
object WriteTextUpdate as public but open it in ReadAllFiles
Public WriteTxtUpdate as StreamWriter Sub ReadAllFiles
WriteTxtUpdate = File.CreateText File(........)
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush WriteTxtUpdate. Close
End Sub
You won't get an error this way, but the old file is destoyed w/ every call.
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message
news:uk******** ******@TK2MSFTN GP15.phx.gbl... Thanks for the reply. This is my code. As you can see, it recurses by calling itself repeatedly. And then the sub ReadAllFiles tidies up by closing the stream. My problem is that the 2nd time it runs it errors on line ".WriteLine(sFi le) in the ReadDirs Sub.
Sub ReadAllFiles
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush WriteTxtUpdate. Close
End Sub
Sub ReadDirs(ByVal Sourcedir As String, ByVal recursive As Boolean)
Sourcedir &= Path.DirectoryS eparatorChar
If fRecursive Then For Each sDir In Directory.GetDi rectories(Sourc edir) sDirInfo = New DirectoryInfo(s Dir) ReadDirs(sDirIn fo.FullName, fRecursive) sDirInfo = Nothing Next End If
With WriteTxtUpdate For Each sFile In Directory.GetFi les(Sourcedir) .WriteLine(sFil e) Next End With
End Sub
-- Bob Hollness
------------------------------------- I'll have a B please Bob
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote in message news:e0******** *****@TK2MSFTNG P12.phx.gbl...I think I'm a little confused at what you need to do. But your problem lies in
If you declare like this:
Public Writer As StreamWriter
Public Sub1() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub2() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub DoSomethingThat MustCloseFile Writer.Close Writer = Nothing End Sub
Now this way of doing it opens the file if it was closed. And uses the same file if it was already opened. I think this is what you are talking about doing. If not, can you post some sample code that shows the problem more?
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message news:Ok******** ******@TK2MSFTN GP14.phx.gbl... Hi all.
I have a Sub that calls another sub. Both subs use a common object, so I used Public to declare it at the top of the module, as below.
Public Writer As StreamWriter = File.CreateText (Application.St artupPath & "\Update.tx t")
The first time my Sub runs it works fine. But the second time it fails telling me "Cannot write to a closed TextWriter. I am guessing that this is because the Public section is only read once instance of the application. I have to close the TextWriter so that I can use the file in another process. Any idea how I can either ensure that the Public section is re-read, or, provide the TextWriter to the 2nd Sub?
-- Bob Hollness
------------------------------------- I'll have a B please Bob
You are talking about "2nd time" meaning the second time you call the
function ReadAllFiles right. If that is the case then my solution in my
previous post solves the problem. After you close WriteTextUpdate you have
to open it again before you use it. Two ways to solve it.
1. Declare WriteTextUpdate inside ReadAllFiles and pass it into ReadDirs
2. (Probably a better way for this case, as I stated before) Define then
object WriteTextUpdate as public but open it in ReadAllFiles
Public WriteTxtUpdate as StreamWriter Sub ReadAllFiles
WriteTxtUpdate = File.CreateText File(........)
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush WriteTxtUpdate. Close
End Sub
You won't get an error this way, but the old file is destoyed w/ every call.
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message
news:uk******** ******@TK2MSFTN GP15.phx.gbl... Thanks for the reply. This is my code. As you can see, it recurses by calling itself repeatedly. And then the sub ReadAllFiles tidies up by closing the stream. My problem is that the 2nd time it runs it errors on line ".WriteLine(sFi le) in the ReadDirs Sub.
Sub ReadAllFiles
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush WriteTxtUpdate. Close
End Sub
Sub ReadDirs(ByVal Sourcedir As String, ByVal recursive As Boolean)
Sourcedir &= Path.DirectoryS eparatorChar
If fRecursive Then For Each sDir In Directory.GetDi rectories(Sourc edir) sDirInfo = New DirectoryInfo(s Dir) ReadDirs(sDirIn fo.FullName, fRecursive) sDirInfo = Nothing Next End If
With WriteTxtUpdate For Each sFile In Directory.GetFi les(Sourcedir) .WriteLine(sFil e) Next End With
End Sub
-- Bob Hollness
------------------------------------- I'll have a B please Bob
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote in message news:e0******** *****@TK2MSFTNG P12.phx.gbl...I think I'm a little confused at what you need to do. But your problem lies in
If you declare like this:
Public Writer As StreamWriter
Public Sub1() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub2() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub DoSomethingThat MustCloseFile Writer.Close Writer = Nothing End Sub
Now this way of doing it opens the file if it was closed. And uses the same file if it was already opened. I think this is what you are talking about doing. If not, can you post some sample code that shows the problem more?
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message news:Ok******** ******@TK2MSFTN GP14.phx.gbl... Hi all.
I have a Sub that calls another sub. Both subs use a common object, so I used Public to declare it at the top of the module, as below.
Public Writer As StreamWriter = File.CreateText (Application.St artupPath & "\Update.tx t")
The first time my Sub runs it works fine. But the second time it fails telling me "Cannot write to a closed TextWriter. I am guessing that this is because the Public section is only read once instance of the application. I have to close the TextWriter so that I can use the file in another process. Any idea how I can either ensure that the Public section is re-read, or, provide the TextWriter to the 2nd Sub?
-- Bob Hollness
------------------------------------- I'll have a B please Bob
How can I declare it and then pass it to the Sub? This is new to me...
sorry..... :-(
--
Bob Hollness
-------------------------------------
I'll have a B please Bob
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote
in message news:ul******** ******@TK2MSFTN GP14.phx.gbl... You are talking about "2nd time" meaning the second time you call the function ReadAllFiles right. If that is the case then my solution in my previous post solves the problem. After you close WriteTextUpdate you have to open it again before you use it. Two ways to solve it.
1. Declare WriteTextUpdate inside ReadAllFiles and pass it into ReadDirs 2. (Probably a better way for this case, as I stated before) Define then object WriteTextUpdate as public but open it in ReadAllFiles
Public WriteTxtUpdate as StreamWriter
Sub ReadAllFiles
WriteTxtUpdate = File.CreateText File(........)
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush WriteTxtUpdate. Close
End Sub
You won't get an error this way, but the old file is destoyed w/ every call. Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message news:uk******** ******@TK2MSFTN GP15.phx.gbl... Thanks for the reply. This is my code. As you can see, it recurses by calling itself repeatedly. And then the sub ReadAllFiles tidies up by closing the stream. My problem is that the 2nd time it runs it errors on line ".WriteLine(sFi le) in the ReadDirs Sub.
Sub ReadAllFiles
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush WriteTxtUpdate. Close
End Sub
Sub ReadDirs(ByVal Sourcedir As String, ByVal recursive As Boolean)
Sourcedir &= Path.DirectoryS eparatorChar
If fRecursive Then For Each sDir In Directory.GetDi rectories(Sourc edir) sDirInfo = New DirectoryInfo(s Dir) ReadDirs(sDirIn fo.FullName, fRecursive) sDirInfo = Nothing Next End If
With WriteTxtUpdate For Each sFile In Directory.GetFi les(Sourcedir) .WriteLine(sFil e) Next End With
End Sub
-- Bob Hollness
------------------------------------- I'll have a B please Bob
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote in message news:e0******** *****@TK2MSFTNG P12.phx.gbl...I think I'm a little confused at what you need to do. But your problem lies in
If you declare like this:
Public Writer As StreamWriter
Public Sub1() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub2() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub DoSomethingThat MustCloseFile Writer.Close Writer = Nothing End Sub
Now this way of doing it opens the file if it was closed. And uses the same file if it was already opened. I think this is what you are talking about doing. If not, can you post some sample code that shows the problem more?
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message news:Ok******** ******@TK2MSFTN GP14.phx.gbl... Hi all.
I have a Sub that calls another sub. Both subs use a common object, so I used Public to declare it at the top of the module, as below.
Public Writer As StreamWriter = File.CreateText (Application.St artupPath & "\Update.tx t")
The first time my Sub runs it works fine. But the second time it fails telling me "Cannot write to a closed TextWriter. I am guessing that this is because the Public section is only read once instance of the application. I have to close the TextWriter so that I can use the file in another process. Any idea how I can either ensure that the Public section is re-read, or, provide the TextWriter to the 2nd Sub?
-- Bob Hollness
------------------------------------- I'll have a B please Bob
How can I declare it and then pass it to the Sub? This is new to me...
sorry..... :-(
--
Bob Hollness
-------------------------------------
I'll have a B please Bob
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote
in message news:ul******** ******@TK2MSFTN GP14.phx.gbl... You are talking about "2nd time" meaning the second time you call the function ReadAllFiles right. If that is the case then my solution in my previous post solves the problem. After you close WriteTextUpdate you have to open it again before you use it. Two ways to solve it.
1. Declare WriteTextUpdate inside ReadAllFiles and pass it into ReadDirs 2. (Probably a better way for this case, as I stated before) Define then object WriteTextUpdate as public but open it in ReadAllFiles
Public WriteTxtUpdate as StreamWriter
Sub ReadAllFiles
WriteTxtUpdate = File.CreateText File(........)
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush WriteTxtUpdate. Close
End Sub
You won't get an error this way, but the old file is destoyed w/ every call. Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message news:uk******** ******@TK2MSFTN GP15.phx.gbl... Thanks for the reply. This is my code. As you can see, it recurses by calling itself repeatedly. And then the sub ReadAllFiles tidies up by closing the stream. My problem is that the 2nd time it runs it errors on line ".WriteLine(sFi le) in the ReadDirs Sub.
Sub ReadAllFiles
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush WriteTxtUpdate. Close
End Sub
Sub ReadDirs(ByVal Sourcedir As String, ByVal recursive As Boolean)
Sourcedir &= Path.DirectoryS eparatorChar
If fRecursive Then For Each sDir In Directory.GetDi rectories(Sourc edir) sDirInfo = New DirectoryInfo(s Dir) ReadDirs(sDirIn fo.FullName, fRecursive) sDirInfo = Nothing Next End If
With WriteTxtUpdate For Each sFile In Directory.GetFi les(Sourcedir) .WriteLine(sFil e) Next End With
End Sub
-- Bob Hollness
------------------------------------- I'll have a B please Bob
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote in message news:e0******** *****@TK2MSFTNG P12.phx.gbl...I think I'm a little confused at what you need to do. But your problem lies in
If you declare like this:
Public Writer As StreamWriter
Public Sub1() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub2() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub DoSomethingThat MustCloseFile Writer.Close Writer = Nothing End Sub
Now this way of doing it opens the file if it was closed. And uses the same file if it was already opened. I think this is what you are talking about doing. If not, can you post some sample code that shows the problem more?
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message news:Ok******** ******@TK2MSFTN GP14.phx.gbl... Hi all.
I have a Sub that calls another sub. Both subs use a common object, so I used Public to declare it at the top of the module, as below.
Public Writer As StreamWriter = File.CreateText (Application.St artupPath & "\Update.tx t")
The first time my Sub runs it works fine. But the second time it fails telling me "Cannot write to a closed TextWriter. I am guessing that this is because the Public section is only read once instance of the application. I have to close the TextWriter so that I can use the file in another process. Any idea how I can either ensure that the Public section is re-read, or, provide the TextWriter to the 2nd Sub?
-- Bob Hollness
------------------------------------- I'll have a B please Bob
Like I said, I'd probably declare it like the code I showed since you are
doing it recursive and all.
But...
Sub ReadAllFiles
Dim WriteTxtUpdateF orThisSub as StreamWriter = File.Create(... .)
Call ReadDirs(WHATEV ER_PATH, True, WriteTxtUpdateF orThisSub)
WriteTxtUpdateF orThisSub.Flush
WriteTxtUpdateF orThisSub.Close
End Sub
Sub ReadDirs(ByVal Sourcedir As String, ByVal recursive As Boolean, ByRef
WriteTxtUpdate as StreamWriter)
Sourcedir &= Path.DirectoryS eparatorChar
If fRecursive Then
For Each sDir In Directory.GetDi rectories(Sourc edir)
sDirInfo = New DirectoryInfo(s Dir)
ReadDirs(sDirIn fo.FullName, fRecursive, WriteTxtUpdate)
sDirInfo = Nothing
Next
End If
With WriteTxtUpdate
For Each sFile In Directory.GetFi les(Sourcedir)
.WriteLine(sFil e)
Next
End With
End Sub
"Bob Hollness" <bo*@blockbuste r.com> wrote in message
news:en******** ******@TK2MSFTN GP12.phx.gbl... How can I declare it and then pass it to the Sub? This is new to me... sorry..... :-(
-- Bob Hollness
------------------------------------- I'll have a B please Bob
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote in message news:ul******** ******@TK2MSFTN GP14.phx.gbl... You are talking about "2nd time" meaning the second time you call the function ReadAllFiles right. If that is the case then my solution in my previous post solves the problem. After you close WriteTextUpdate you have to open it again before you use it. Two ways to solve it.
1. Declare WriteTextUpdate inside ReadAllFiles and pass it into ReadDirs 2. (Probably a better way for this case, as I stated before) Define then object WriteTextUpdate as public but open it in ReadAllFiles
Public WriteTxtUpdate as StreamWriter
Sub ReadAllFiles
WriteTxtUpdate = File.CreateText File(........)
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush WriteTxtUpdate. Close
End Sub
You won't get an error this way, but the old file is destoyed w/ every call. Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message news:uk******** ******@TK2MSFTN GP15.phx.gbl... Thanks for the reply. This is my code. As you can see, it recurses by calling itself repeatedly. And then the sub ReadAllFiles tidies up by closing the stream. My problem is that the 2nd time it runs it errors on line ".WriteLine(sFi le) in the ReadDirs Sub.
Sub ReadAllFiles
Call ReadDirs(WHATEV ER_PATH, True)
WriteTxtUpdate. Flush WriteTxtUpdate. Close
End Sub
Sub ReadDirs(ByVal Sourcedir As String, ByVal recursive As Boolean)
Sourcedir &= Path.DirectoryS eparatorChar
If fRecursive Then For Each sDir In Directory.GetDi rectories(Sourc edir) sDirInfo = New DirectoryInfo(s Dir) ReadDirs(sDirIn fo.FullName, fRecursive) sDirInfo = Nothing Next End If
With WriteTxtUpdate For Each sFile In Directory.GetFi les(Sourcedir) .WriteLine(sFil e) Next End With
End Sub
-- Bob Hollness
------------------------------------- I'll have a B please Bob
"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote in message news:e0******** *****@TK2MSFTNG P12.phx.gbl... I think I'm a little confused at what you need to do. But your problem lies in
If you declare like this:
Public Writer As StreamWriter
Public Sub1() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub2() if Writer is Nothing then Wrier = File.CreateText (Application.St artupPath & "\Update.tx t") end if 'Do Something End Sub
Public Sub DoSomethingThat MustCloseFile Writer.Close Writer = Nothing End Sub
Now this way of doing it opens the file if it was closed. And uses the same file if it was already opened. I think this is what you are talking about doing. If not, can you post some sample code that shows the problem more?
Chris
"Bob Hollness" <bo*@blockbuste r.com> wrote in message news:Ok******** ******@TK2MSFTN GP14.phx.gbl... > Hi all. > > I have a Sub that calls another sub. Both subs use a common object, > so I used Public to declare it at the top of the module, as below. > > Public Writer As StreamWriter = > File.CreateText (Application.St artupPath & "\Update.tx t") > > The first time my Sub runs it works fine. But the second time it > fails telling me "Cannot write to a closed TextWriter. I am guessing > that this is because the Public section is only read once instance of > the application. I have to close the TextWriter so that I can use the > file in another process. Any idea how I can either ensure that the > Public section is re-read, or, provide the TextWriter to the 2nd Sub? > > -- > Bob Hollness > > ------------------------------------- > I'll have a B please Bob >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nel |
last post by:
I have a question related to the "security" issues posed by Globals ON.
It is good programming technique IMO to initialise variables, even if it's
just
$foo = 0;
$bar = "";
Surely it would be better to promote better programming than rely on PHP to
compensate for lazy programming?
|
by: Craig Bailey |
last post by:
Anyone recommend a good script editor for Mac OS X?
Just finished a 4-day PHP class in front of a Windows machine, and liked
the editor we used. Don't recall the name, but it gave line numbers as
well as some color coding, etc.
Having trouble finding the same in an editor that'll run on OS X.
--
Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
|
by: Chris |
last post by:
Sorry to post so much code all at once but I'm banging my head against
the wall trying to get this to work!
Does anyone have any idea where I'm going wrong?
Thanks in advance and sorry again for adding so much code...
<TABLE border="1" bordercolor="#000000" cellspacing="0">
<TR>
|
by: James |
last post by:
My form and results are on one page.
If I use :
if ($Company) {
$query = "Select Company, Contact
From tblworking
Where ID = $Company
Order By Company ASC";
}
|
by: Alan Walkington |
last post by:
Folks:
How can I get an /exec'ed/ process to run in the background on an XP box?
I have a monitor-like process which I am starting as
'exec("something.exe");' and, of course the exec function blocks until
something.exe terminates. Just what I /don't/ want. (Wouldn't an & be
nice here! Sigh)
I need something.exe to disconnect and run in the background while I
| |
by: John Ryan |
last post by:
What PHP code would I use to check if submitted sites to my directory
actually exist?? I want to use something that can return the server
code to me, ie HTTP 300 OK, or whatever. Can I do this with sockets??
|
by: James |
last post by:
What is the best method for creating a Web Page that uses both
PHP and HTML ?
<HTML>
BLA
BLA
BLA
BLA
BLA
|
by: Beowulf |
last post by:
Hi Guru's,
I have a query regarding using PHP to maintain a user profiles list. I
want to be able to have a form where users can fill in their profile
info (Name, hobbies etc) and attach an image, which will upload the
record to a mySql db so users can then either view all profiles or
query.. I.e. show all males in UK, all femails over 35 etc.
Now, I'm not asking for How to do this but more what would be the best
way? I've looked at...
|
by: joost |
last post by:
Hello,
I'm kind of new to mySQL but more used to Sybase/PHP
What is illegal about this query or can i not use combined query's in mySQL?
DELETE FROM manufacturers
WHERE manufacturers_id NOT IN ( SELECT manufacturers_id
FROM
products )
|
by: presspley |
last post by:
I have bought the book on advanced dreamweaver and PHP recently. I
have installed MySQL and PHP server but am getting an error on the
$GET statement show below. It says there is a problem with the
variable $GET but $GET is not a variable, I thought it came from the
page that calls the PHP file?
if(($_GET)==""){
this gets an error
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |