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.

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

   ' By the way, (4,1,9,3) is "E2:J4". Row 2 and 3 in that spreadsheet
contains numbers, row 4 contains text.

   A=OBDef(2,0) ' This doesn't work.
See above, it is an array of arrays, this is not a two dimensional array.

Okay, so far, no good.
When I look at the variables with "Övervakaren" (in Swedish, I don't have a
clue what it might be called in English, but I am talking about the tool
that helps me to see the content of variables while I step through the
macro, the button that allows me to select variables to watch in the Basic API thing, has a pair of glasses on it and F7 does the same thing), it seems
like OBDef(2)(0) is a Variant/String. What's the difference between
Variant/String and just String?
A variant can hold any type. So, you have a variant that references a string.
So my question is really something like this:

How do I, in this meaningless example, make the content of OBDef(2,0), which is a String variable, originally some text in cell E4 in spreadsheet "Blah",
to be copied to A, which is an ordinary String?
Does th example shown above help? If not...
oRow() = oBDef(2)
A = oRow(0)
What I would like to achieve is to copy a CellRange to a 2-dimensional
variable. Since some rows contains numbers and other contains text I though
that the type "Variant" could be useable, but obviously not...

No I really have to copy the CellRange cell by cell?
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())


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
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.


Johnny


--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to