I am trying to write data to a binary file using the Print() method, but when I run it I get the System.IO exception Bad File Mode. Does anybody have an idea of what's going wrong here? Here's the code for the FileOpen declaration, that开发者_StackOverflow社区 might have something to do with it? Thanks
FileOpen(filenumber, "path to file", OpenMode.Binary, OpenAccess.Write, OpenShare.LockReadWrite)
Print(filenumber, expression(variable))
Why are you using Print
in the first place? That function is included for backwards compatibility with VB 6 applications. If you're writing a new application in VB.NET, you should be using a different function.
The easiest way to get off the ground quickly is using the My.Computer.FileSystem
object to read and write to files. This even provides better performance than the legacy functions like FileOpen
and Print
. More explanation and sample code is available here on MSDN. Specifically:
- Reading from Files in Visual Basic
- Writing to Files in Visual Basic
精彩评论