开发者

Does the Print() method in VB.NET work with files opened with Binary access?

开发者 https://www.devze.com 2023-02-15 06:05 出处:网络
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 c

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
0

精彩评论

暂无评论...
验证码 换一张
取 消