J
John Dann
I'm tripping over a silly little problem when trying to read a text
file, but can't see the fix. Outline code is:
----------------------------------------------------
FS=New FileStream(filename, filemode)
Dim SR as New Streamreader(FS)
Try
Read file
Catch ex as exception
Whatever
Finally
SR.Close()
End Try
-------------------------------------------------
If filename does not exist then the first line above throws an error.
But if I place the FS= and Dim SR lines inside the Try block then SR
seems to go out of scope in the Finally section.
I guess there's several solutions to this like putting the whole code
block inside an If block, ie
If File.Exists(filename) Then
As above
End If
But I can't help feeling I'm missing something obvious in the way this
ought to be done.
JGD
file, but can't see the fix. Outline code is:
----------------------------------------------------
FS=New FileStream(filename, filemode)
Dim SR as New Streamreader(FS)
Try
Read file
Catch ex as exception
Whatever
Finally
SR.Close()
End Try
-------------------------------------------------
If filename does not exist then the first line above throws an error.
But if I place the FS= and Dim SR lines inside the Try block then SR
seems to go out of scope in the Finally section.
I guess there's several solutions to this like putting the whole code
block inside an If block, ie
If File.Exists(filename) Then
As above
End If
But I can't help feeling I'm missing something obvious in the way this
ought to be done.
JGD