Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fileopen for Output Permission Denied 1

Status
Not open for further replies.

kennedymr2

Programmer
Joined
May 23, 2001
Messages
594
Location
AU
I have written a program in VB Express 2008, which creates an output file every 10 seconds. eg

FileOpen(1, c:\test.txt", OpenMode.Output)
PrintLine(1, "888888")
'eg writing out about 24 lines of code...
FileClose(1)

There is another program written in VB6 which reads this file every 5 seconds.
I have had this senario running for years using vb6 in both programs, and very rarely get a clash.
But now have written the writer in VB Express 2008.

The vb program reading the file keeps coming up with permission denied., when it tries to open the file.. all the time...

???? Does vb Express 2008, using the code above put some sort of lock on the file for a period.. ie it does not quickly release ???? or something..

Would appreciate some advice as to the problem or a better way of doing it..

Regards Kennedymr2
\








 
Try something like:
Code:
FileOpen(1, "c:\test.txt", OpenMode.Output, OpenAccess.ReadWrite, OpenShare.Shared)

Also, you will eventually want to switch to the System.IO namespace in .Net instead of using VB6 style file access methods.
 
Thanks once again RiverGuy...

I tried this on my machine and it seemed to work without a problem.I can see how this should relieve the problem !!

I did forget to mention one thing.. my program is actually running on a friends machine with the following senario.I have not tested it on his machine yet.

His setup is..
The vb program is running on a windows 2000 computer

The vb express program is running on another computer under xp, as Express will only run under xp. i have mapped a drive to the windows 2000 computer and called it x:\ The express is writing the file to the x:\ drive on the windows 2000 computer.Could this be introducing a furthur problem. ???
Cannot test it until he sets his computer up in about 10 hours.

regards Kennedymr2





 
RiverGuy.. Thanks for your quick reply

I did not realize that it may work on the windows 2000 computer. Will give this a try later today.

As you sujjested i have looked at

Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
I am interested how i can use this and not get the locking permission problems that i encounted in the original problem. There seems to be a .filemode
 
I don't see the FileMode property. However, I did test the following code in a timer with half second intervals. I could open up my text file in Notepad no problem, while continuing to write new lines of text. You'd have to test it over that mapped drive to see how it works.
Code:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim fs As New System.IO.FileStream("c:\myfile.txt", IO.FileMode.Append, IO.FileAccess.Write, IO.FileShare.Read)
        Dim s As String = "hello world " & DateTime.Now.ToString & ControlChars.CrLf
        fs.Write(New System.Text.UTF8Encoding(True).GetBytes(s), 0, s.Length)
        fs.Close()
    End Sub
 
RiverGuy...

Have tried it on Windows 2000 with the latest Framework.. and yes..its works 100%..

Now i have resolved this.. i will run the program on the windows 2000 computer and therefor eliminate the ^possible xp mapped drive problem.

I have now done more testing using your ideas and i seem to have resolved it all.

I really appreciate the detailed help and interest you have shown in helping me with this problem.

Its a pretty anxious time moving from years of vb6 to vb.net. !!!

Many thanks..Regards Kennedymr2
 
No problem. Good luck in moving your projects to .Net.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top