Issue 47216 - Length specification on declaration of String variables
Summary: Length specification on declaration of String variables
Alias: None
Product: General
Classification: Code
Component: scripting (show other issues)
Version: 680m91
Hardware: PC Windows XP
: P3 Trivial with 1 vote (vote)
Target Milestone: AOO Later
Assignee: AOO issues mailing list
QA Contact:
Depends on:
Reported: 2005-04-12 05:47 UTC by mjneedles
Modified: 2017-05-20 11:31 UTC (History)
1 user (show)

See Also:
Latest Confirmation in: ---
Developer Difficulty: ---


Note You need to log in before you can comment on or make changes to this issue.
Description mjneedles 2005-04-12 05:47:18 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.
Comment 1 mjneedles 2005-08-01 03:55:25 UTC
any activity on this yet?
Comment 2 noel.power 2005-09-02 08:48:27 UTC
reassign to ab
Comment 3 ab 2005-09-02 13:36:41 UTC
ab->mjneedles: In my m125 build this declaration at least compiles.
Could you add some example code to show what exactly fails?
Comment 4 mjneedles 2005-09-03 06:23:10 UTC
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
Comment 5 ab 2006-03-21 11:41:43 UTC
STARTED, -> OOo later
Comment 6 Marcus 2017-05-20 11:31:07 UTC
Reset assigne to the default "".