Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
The Struggle continues, I am now getting an IOExeception when writing to the results file using StreamWriter. The ile 'C:\Users\glennp\Desktop\VB2008_Test_Rig_modded with SendAndWait - SaveWorking\VB2008_Test_Rig\bin\Debug\FailResults.CSV' because it is being used by another process." I am closing the stream after I have written out data by
VB
'all pass
If ((VoltageTestBool = False) And (TimeKeepTestBool = False) And (LCDtestBool = False) And (RFtestBool = False) And (RFxtalBool = False) And (RFtestHighBool = False) And (QuiescentBool = False)) Then
    Result_Save += "Unit Passed," + DateAndTime.Now
    outPass.WriteLine(Result_Save)
    outPass.Close()
End If
'volts fail
If ((VoltageTestBool = True) And (TimeKeepTestBool = False) And (LCDtestBool = False) And (RFtestBool = False) And (RFxtalBool = False) And (RFtestHighBool = False) And (QuiescentBool = False)) Then
    Result_Save += "Voltge Test Failed," + DateAndTime.Now
    outFail.WriteLine(Result_Save)
    outFail.Close()
    StopTests = True
End If

I do not have it open in another program (the problem did start after I opened the file in Excel and closed it) since then I have power cycled my machine to ensure any trace closed down. I checked the file permissions no read only on them?
Any one any ideas?
Glenn
Posted

1 solution

Try using File.AppendAllText() instead which handles open/write/close for you : http://msdn.microsoft.com/en-us/library/ms143356%28v=vs.110%29.aspx[^]
 
Share this answer
 
Comments
glennPattonWork3 14-Apr-14 6:34am    
Solves that problem!
glennPattonWork3 14-Apr-14 8:36am    
Hi,
Gets around permission problems, but will only save two records! I have has a good fiddle with it. And it seems only to allow the creation of the file and a second entry even if I use
If(File.Exists = True) Then
blah!
Blah!
End If
Mehdi Gholam 14-Apr-14 10:02am    
Then the problem is elsewhere since File.AppendAllText() does not keep the file open.
glennPattonWork3 14-Apr-14 10:07am    
Not to worry my logic was faulty !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900