I am newbie with OOobasic building macros for LibreOffice.
I am testing the method .getDataArray() As you can see in the example, the array get loaded with the values, but later, I want to make an iteration with this array until the end of the array with UBound(), but UBound is always 0 and I don’t know why. As you can see getDataArray get the values of a range. In my case, my range is a a simple row from A1 to AH1.
In the loop ‘For’ If I change the UBound() by the variable ‘Columnas’ then the iteration works. Any ideas why I am doig wrong? Copy and pasted in your LibreOffice and run it.
Please, be specific. If you have the solution send me the code.
Sub TestArray2
Dim oSheet as object
Dim Simple_Row_array() As Variant
Dim SimpleRow 'As we don't know how long is we don't dimension yet.
Dim Columnas as Long
oSheet = ThisComponent.Sheets.getByName("Concedidos")
Dim oRange As Object : oRange = oSheet.getCellRangebyName( "A1:AH1" )
Columnas = oRange.Columns.getCount() - 1'Get the number of columns. getColumn, getRow existe.
Redim Preserve Simple_Row_array (0 To Columnas)
Redim Preserve SimpleRow (Columnas)
Simple_Row_array() = oRange.getDataArray() 'Asign values to an array
For i = LBound(Simple_Row_array()) To UBound(Simple_Row_array())
SimpleRow(i) = Simple_Row_array(0)(i)
Next i
Print UBound(SimpleRow()) 'It display the amount of values correctly
Print UBound(Simple_Row_array(),1)'it displays always 0.
Print UBound(Simple_Row_array())'it displays always 0.
End Sub