When using the PUT statement with a string on a random access file, then the 2 length bytes ar written and the string gets truncated the last 2 characters.
Created attachment 163201 [details] document with macro jc_bourg, are you using LO Basic, a random file and the "put" operation? OpenOffice.org Macros Explained (OOME_3_0.pdf, <http://www.pitonyak.org/OOME_3_0.pdf>), section 8.8 "Reading and writing data" says of random files and operation "put": If the data variable is a Variant, an integer identifying the data type precedes the data. and When Put places a string as a Variant, it actually writes the VarType, the string length, and then the string. My experiment in a local build of commit e54ff4c1 on debian-buster gives results like Andrew Pitonyak described. Neither a String nor a Variant shows truncation of the last two characters. Macro "one" in the attached demo01.odt is the experiment. I am setting status NEEDINFO. jc_bourg, please set bug status back to UNCONFIRMED when you reply.
Created attachment 163209 [details] document with macro Trying again ... after I saved the file.
Created attachment 163504 [details] Sample VB code Please find attached a sample basic code
Created attachment 163505 [details] sample output file hex dump: file name: Test.DAT mime type: 0000-0010: 05 00 54 65-73 05 00 54-65 73 05 00-54 65 73 74 ..Tes..T es..Test 0000-0011: 33 3
i did upload a sample basic code, out file and hex dump that produces the error. Note: Setting the record length to 7, will no longer truncate the text strings. But having the 2 byte length in each record, does not make any sense, in a fixed length random access file.
[Automated Action] NeedInfo-To-Unconfirmed
I suspect that the the two-byte length has been a feature of LO for a long time (the book I cited is from 2016, and it was already version 3) and that there are macros which rely on this feature. Thus I think we should keep the present behavior. To invite further comments, I am adding keyword needsUXEval. Meanwhile, the language provides other open modes and other output operators which may better suit your needs.
What do you think, Alain & Andrew?
Not a bug: - If the variable being written is a variable-length string, Put writes a 2-byte descriptor containing the string length and then the variable. The record length specified by the Len clause in the Open statement must be at least 2 bytes greater than the actual length of the string. as per https://docs.microsoft.com/fr-fr/office/vba/language/reference/user-interface-help/put-statement - The Put statement behaves differently, depending on the type of file you're using. Random files: The first two bytes written indicate the length of the string. Then the Put statement writes the number of characters specified by that length. If variableName is not initialized, the Put statement writes a string of length 0. as per https://help.hcltechsw.com/dom_designer/9.0.1/appdev/LSAZ_PUT_STATEMENT.html