Link to home
Get AccessLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on open text file

how can I open a text file and leave it open so that if I try to write to the file I get file already open error..
I would like to test a few function but I need the (already open)
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

Dim sw1 as StreamWriter = New StreamWriter(strPathAndFilename)
Dim sw2 as StreamWriter = New StreamWriter(strPathAndFilename)
You will need to import System.IO, if not already imported.
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
I am just learning vb, but I came across this that might work -

Dim ff As Integer
On Error GoTo errHandler

ff = FreeFile
Open "c:\sample.txt" For Random Access Write As #ff
Close #ff

    MsgBox "File is Open"

Hello madhatter5501

While i have no intention to discourage your attitude to be helpful, may i bring it to your attention that this question is being asked in Microsoft Visual Basic.NET zone and your answer caters to Microsoft Visual Basic 5.0 / 6.0, the older versions prior to .NET.
thanks for clearing that up :)  sorry for the incorrect answer to the question.