Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extended KotD #9: _WRITEFILE
#1
The last of the new keywords and enhancements for v3.12 is _WriteFile.  Like _ReadFile$, it's a simple shortcut which can help reduce multiple commands into one simple process.

In the past, one would have to do the following to write a binary file to the drive:

Code: (Select All)
F = FreeFile
Open "temp.txt" For Output As #F
Close F
Open "temp.txt" For Binary As #F
PUT #F, 1, your_string$
Close #F
Nothing overly complex, but still a good bit of typing , with even more typing required if Option _Explicit is used in the program to define all those variables (such as the F to hold the free file handle).

Now, however, since v3.12, one can replace all the above code with the following:
Code: (Select All)
_WriteFile "temp.txt", your_string$


No need to get a file handle.  No need to open the file FOR OUTPUT to make certain it's blank and you're not corrupting a previous file with the same name.  No need to close that handle and then reopen another FOR BINARY to write the file...only to have to close it once again.

Just a simple _WriteFile file$, string_to_write$

That's all there is for this little shortcut command!  Smile
Reply




Users browsing this thread: 1 Guest(s)