| View previous topic :: View next topic |
| Author |
Message |
richhill OOo Advocate


Joined: 16 Jun 2004 Posts: 418 Location: Mesa, AZ
|
Posted: Fri Apr 08, 2005 9:42 pm Post subject: Arrays inside user-defined types |
|
|
Excel VBA allow arrays in customized data types
| Code: | Type MyArray
id As String
Comps(50) As Double
End Type
|
Apparently, OOo does not allow this type of array construct inside a Type.
What is the workaround? _________________ OOo Calc tips: http://www.openofficetips.com |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Sat Apr 09, 2005 8:20 am Post subject: |
|
|
Copy, Paste and then Run this example. See what happens.
I did this in OOo 1.1.4 on Win XP Pro.
| Code: |
Type MyDooDad
cID
aComps
End Type
Sub Main
' Create a MyDooDad, set its ID.
oMyDooDad1 = MakeMyDooDad( "Fred" )
' Now set some of its array elements.
oMyDooDad1.aComps( 0 ) = "house"
oMyDooDad1.aComps( 1 ) = "houses"
oMyDooDad1.aComps( 2 ) = "mouse"
oMyDooDad1.aComps( 3 ) = "mice"
' Create a MyDooDad, set its ID.
oMyDooDad2 = MakeMyDooDad( "Jane" )
' Now set some of its array elements.
oMyDooDad2.aComps( 0 ) = "goose"
oMyDooDad2.aComps( 1 ) = "geese"
oMyDooDad2.aComps( 2 ) = "loose"
oMyDooDad2.aComps( 3 ) = "lease"
PrintADooDad( oMyDooDad1 )
PrintADooDad( oMyDooDad2 )
End Sub
' This function dynamically creates and returns a MyDooDad.
Function MakeMyDooDad( cID )
Dim oMyDooDad As MyDooDad
With oMyDooDad
.cID = cID
.aComps = DimArray( 50 )
End With
MakeMyDooDad = oMyDooDad
End Function
Sub PrintADooDad( oMyDooDad )
Print oMyDooDad.cId + " has a " + oMyDooDad.aComps( 0 ) + " with a " + oMyDooDad.aComps( 2 )
End Sub
|
Comming from a background of using languages like LISP, Python, etc., I prefer the style of using functions that dynamically allocate things rather than statically declare them. Therefore, I never use the Dim statement, unless absolutely necessary. The actual semantics of objects in OOo Basic match my style of use. However, the question of which style to write your code, is purely, a question of style.
The Dim statement only makes you think you are statically allocating an instance with local extent (as opposed to local scope). Hence, the MakeMyDooDad function, while it uses a Dim statement, actually returns the object that it created, thus proving that while the variable name has local scope, the variable is merely a reference to an underlying object that has dynamic extent.
See also....
Structs in StarBasic
http://www.oooforum.org/forum/viewtopic.phtml?t=18948
http://www.oooforum.org/forum/viewtopic.php?t=12032
http://www.oooforum.org/forum/viewtopic.php?t=10967
Array Semantics
http://www.oooforum.org/forum/viewtopic.php?t=4615
http://www.oooforum.org/forum/viewtopic.php?t=4608
Any reason to use Dim statement?
http://www.oooforum.org/forum/viewtopic.php?t=5845 _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
richhill OOo Advocate


Joined: 16 Jun 2004 Posts: 418 Location: Mesa, AZ
|
Posted: Sat Apr 09, 2005 10:25 am Post subject: |
|
|
DannyB,
I thank you for the detailed answer to my question. I'll respond later today - as I have also been doing some experimentation of my own. It is all related to developing a OOo Calc Add-In for handing large numbers.
right now - I'm doing a makeover of my daughter's bedroom
All the best!
Dave (richhill) _________________ OOo Calc tips: http://www.openofficetips.com |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|