Apache OpenOffice (AOO) Bugzilla – Issue 47216
Length specification on declaration of String variables
Last modified: 2017-05-20 11:31:07 UTC
In all flavors of MS Basic, especially VisualBasic, one declares a fixed-length string variable by the syntax Dim sVar as String * <bytecount> This does not work in OOo, and makes it difficult (impossible?) to define a fixed-length composite variable, for example, with Type/End Type. This is useful in creating scripts to work with random-access datafiles with fixed-length records. Example declaration: Type tDBFRecord sDeleted as string * 1 ' "*" or " " iRecId as Integer sFullName as String * 35 ' Name sAddr1 as String * 35 sAddr2 as String * 35 sCity as String * 25 sState as String * 5 sPostal as String * 10 sCtryCode as Byte sPhone1 as String * 15 sPhone2 as String * 15 sEmail as String * 64 sNotes as String * 60 End Type REM the above record would have a Len() of 303 Its length is indeterminate as OOo Basic currently stands. Len does not work on it, and I know of no other method to determine how much space it occupies in memory. I have conversed on the users list with Andrew Pitonyak about this and the Len() function issue.
any activity on this yet?
reassign to ab
ab->mjneedles: In my m125 build this declaration at least compiles. Could you add some example code to show what exactly fails?
see issue 47215 REM ***** BASIC ***** ' option explicit Type tUserStruct sString1 as String * 10 nNumber1 as Single iNumber2 as Integer cNumber3 as Currency bTV1 as Boolean end type Sub TestWith Dim myStruct as tUserStruct, iLen1 as Integer, iLen2 as Integer iLen1 = Len(myStruct) ' Fails with runtime error, so comment it out to let the rest run Print "Structured variable length is "; iLen1 With myStruct .sString1 = "This is a test" ' this string is too long for the field and should truncate Print .sString1, len(myStruct.sString1)' BUT... it does not, Len returns 14 .nNumber1 = sqr(3.0) iLen2 = Len(myStruct.nNumber1) print .nNumber1, iLen2 'Prints "1.732051 8" but the length should be 4 bytes for a Single .cNumber3 = 2.23606999 * 2.23606999 Print .cNumber3, len(myStruct.cNumber3) ' prints "5.0000 6", where the length should be 8 bytes .bTV1 = (1 < 1) ' FALSE print .bTV1, len(myStruct.bTV1) ' Prints "False 5" but length should be 2 or 4 (not sure which) End With End Sub
STARTED, -> OOo later
Reset assigne to the default "issues@openoffice.apache.org".