Matt Needles wrote:
Andrew Douglas Pitonyak wrote:
You can not declare a variable to be of a specified length. At least I have never heard of this. You could use an array of characters, but you can not do that directly by definition inside of your own data types :-( The following line does NOT declare a string of length 4. I might consider the acceptance of this form an error unless it is for some kind of compatibility.
Dim s As String * 4
This is the way you do this in VisualBasic. It worked, too, from what I see in the OOo Macro Variable Watch window.
I assumed that it did not work because of the following behavior:
Dim s As String * 4 Print Len(s) REM Prints 0 s = "abced" Print Len(s) REM Prints 5
On a related note, I tried using it with the following macro code and got the error indicated by the REM lines in the code:
Option Explicit
Type tAddrRec sRecType as string * 1 ' "I" for persons, "O" for Organizations sRecStatus as string * 1' "A" active, "D" deleted, "H" held iRecID as integer ' starts with 1 sLName as string * 35 sFname as string * 35 sAddr1 as string * 35 sAddr2 as string * 35 sCity as string * 25 sState as string * 5 sPostal as string * 10 iCtryCode as integer sPhone1 as string * 15 sPhone2 as string * 15 sPhone3 as string * 15 sEmail as string * 64 sNotes as string * 60 End Type
Sub Main Dim myFile as Integer, lRecLen as Long Dim myAddrRec as tAddrRec myFile = FreeFile REM ***** Error occurs on next line. ***** lRecLen = Len(myAddrRec)
The Len() routine expects a String.
Not according to the Help:
Len Function [Runtime]
Returns the number of characters in a string, or the number of bytes that are required to store a variable.
Dim d As Double Print Len(d) REM Print 1 d = 1.443 Print Len(d) REM Print 5
The variable d is converted to a string and then the length of the string is returned. Here is the source code for the function:
RTLFUNC(Len)
{
if ( rPar.Count() != 2 )
StarBASIC::Error( SbERR_BAD_ARGUMENT );
else
{
const String& rStr = rPar.Get(1)->GetString();
rPar.Get(0)->PutLong( (INT32)rStr.Len() );
}
}The reason that you get a property not found error is probably because the object can not be converted to a string. Off hand, I would have expected a method not found error based on the source code, but I am not a source code expert!
I assume that is why you get the error. What did you expect for the length of a user defined type?
I expect the length of the struct I defined. Again, this is the way to do this in VB.
Thanks for your reply, Andrew.
Matt Needles
Matt, I recomend that you file a request for enhancement.
-- Andrew Pitonyak My Macro Document: http://www.pitonyak.org/AndrewMacro.sxw My Macro Book: http://www.hentzenwerke.com/catalog/oome.htm Free Info: http://www.pitonyak.org/oo.php
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
