Thanks for your interesting reply!
Parts of original messages and comments and maybe more questions below:
2007/1/29, Andrew Douglas Pitonyak <[EMAIL PROTECTED]>:
Johnny Andersson wrote:
> Maybe I should put it another way:
>
> Let's say that I have these lines, among others:
>
>
> Dim Ctl As Object
> Dim Doc As Object, Sheet As Object
>
> Dim A As String
> Dim OBDef As Double ' Or whatever, it doesn't seem to matter in this
> case, see further below...
>
> Doc=ThisComponent
> Sheet=Doc.Sheets.getByName("Blah")
>
> OBDef=DataSheet.getCellRangeByPosition(4,1,9,3).getDataArray() ' Now
> OBDef seems to change to Variant.
You have a Calc sheet and you return a cell range based on its position.
Next, you call getDataArray() on the cell range.
The "official" return type is sequence< sequence< any > >, which means
an array of arrays of variants. My opinion is that this should cause an
error because an array of arrays of any should not be assigned to a
double unless the type can be "coerced" or "cast" into the double type.
so, you found a but (that has been around a long time) in StarBasic. I
rarely think about it because it has never caused me any problems. There
might be some reason for the behavior but I am not aware of the reasons.
So it is an array of arrays? That explains what happens when I copy it to a
variable: The variable is shown as MyVariable(x)(y) rather than
MyVariable(x,y) in the "Basic debugger" (I called it "Övervakaren"
before, I just found out that it's actually "Bevakaren", but in this case
it's just about the same thing).
If you wanted the specific values, i expect you to write something like
this:
Dim oData()
Dim oRow()
Dim i%, j%
Dim s$
s = ""
oData() = DataSheet.getCellRangeByPosition(4,1,9,3).getDataArray()
For i=LBound(oData()) To UBound(oData())
oRow() = oData(i)
For j = LBound(oRow()) To UBound(oRow())
s = s & " " & CStr(oRow(j))
Next
s = s & CHR$(10)
Next
MsgBox s
What do you really want to accomplish? Do you want to copy a range of
data from one location to another? If so, you can use methods to
directly copy the data. I have used "cheat" methods such as
oCellRange1.setData(oCellRange2.getData())
No, a function will use the data (and other data) for calculation. The
function will return a value that will be written to another cell. The
function will be in a loop and use three of the values (one
column), different every time.
> Another solution would perharps be to create a struct (as it's called
> in C),
> but is that possible in OpenOffice.org Basic?
Yes, you can create a user defined structure/type. To quote from my
AndrewMacro.odt document.
1.1. User Defined Data Types
As of OOo 1.1.1, you can define your own data types.
Listing 5.51: You can define your own data types.
Type PersonType
FirstName As String
LastName As String
End Type
Sub ExampleCreateNewType
Dim Person As PersonType
Person.FirstName = "Andrew"
Person.LastName = "Pitonyak"
PrintPerson(Person)
End Sub
Sub PrintPerson(x)
Print "Person = " & x.FirstName & " " & x.LastName
End Sub
Wow, I didn't know that! Now I have to rewrite everything macro and
every function I've made so far..!
They are not that many, on the other hand...
In your example above, is the following possible?
Sub ExampleCreateNewType
Dim Person(100) As PersonType
Person(0).FirstName = "Andrew"
Person(0).LastName = "Pitonyak"
PrintPerson(Person(0))
End Sub
And is the following possible?
Type PersonType
FirstName As String
LastName As String
ThingsToDo(9) As String
End Type
And finally, is the following possible?
Type PersonType
FirstName As String
LastName As String
End Type
Type Human
Properties As PersonType
Friends(9) As PersonType
End Type
And even more finally, is there something similar to pointers in
OpenOffice.org Basic?
I gave a presentation at the 2004 OOo Conference in Berlin concerning
creating advanced data types using structures. The examples are in the
presentation available on my web site.
Interesting! I'd better take a look there then!
Thanks for your reply!
Johnny