QB64 Phoenix Edition
Extended KotD #9: _WRITEFILE - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: Official Links (https://qb64phoenix.com/forum/forumdisplay.php?fid=16)
+--- Forum: Learning Resources and Archives (https://qb64phoenix.com/forum/forumdisplay.php?fid=13)
+---- Forum: Keyword of the Day! (https://qb64phoenix.com/forum/forumdisplay.php?fid=49)
+---- Thread: Extended KotD #9: _WRITEFILE (/showthread.php?tid=2713)



Extended KotD #9: _WRITEFILE - SMcNeill - 05-20-2024

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