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 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
Printin 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.FileSystemobject to read and write to files. This even provides better performance than the legacy functions likeFileOpenandPrint. More explanation and sample code is available here on MSDN. Specifically: