|
Post by Walt Decker on Aug 30, 2021 14:26:42 GMT -5
While browsing through file I/O help I noticed this: "In binary access mode, bytes are written to the file or read from the file as characters." I took that to mean that before writing to a binary file(actually all files are binary) numeric variables must be translated to a string variable. Back in the days when disk space was at a premium, Rocky Mountain Basic had some function that translated numeric variable into 1, 2, 4, and 8-byte strings. So I dug into some of my old code and resurrected some of them. NUMBERSTR.DLL is the result. The attached zip contains: NUMBERSTR.DLL NUMBERSTR_INFO.TXT At the bottom of the .txt file is a short demo showing how to use the NUMBERSTR.DLL functions. MAKE_NUMBERS_DLL.ZIP (7.67 KB) PS: I also found this: "Binary mode never writes line delimiters when printing to the file. Line delimiters include carriage returns, which are chr$(13) and line feeds, which are chr$(10)." Is that an error? If not, it needs changing.
|
|
|
Post by Chris Iverson on Aug 30, 2021 15:25:17 GMT -5
Why would that be an error, and why would that need changing?
|
|
|
Post by Brandon Parker on Aug 30, 2021 16:27:20 GMT -5
"Binary mode never writes line delimiters when printing to the file. Line delimiters include carriage returns, which are chr$(13) and line feeds, which are chr$(10)." I am not certain if something changed, but I can tell you with great certainty that you most definitely can write chr$(10) and chr$(13) to a file when it is opened for Binary operations. It is just that the CR LF is not automatically added after printing a "line" to the file. You must absolutely take care of where the file pointer is though... {:0) Brandon Parker
|
|
|
Post by Rod on Aug 30, 2021 16:27:57 GMT -5
I think you are overthinking it Walt. Binary mode writes bytes, a value between 0 and 255. From a programming perspective it is most easily created by using the ascii character that equates to the byte value you want to write. Numbers could by pushed into a format but it is just as easy to write the character string representing the number.
The help file is pointing out that the binary file mode does not ADD delimiters as other file modes do.
|
|
|
Post by Walt Decker on Aug 30, 2021 16:59:09 GMT -5
I misinterpreted. I took that to mean it extracted crlf when writing to the file.
The use of the dll is to produce shorter strings representing the longer string representation of a number, e. g. a 4-byte string representing 12345678 rather than 8 bytes.
This can also be useful in the random access file type when dealing with numbers. The field size could be 1, 2, 4, or 8 depending on the numeric type.
|
|