Iterate over table control

I read and used this topics :

https://ask.libreoffice.org/t/solved-read-values-from-selected-rows-in-a-table-control/40641

I would do a similar thing without selecting any row. I can’t iterate over my table control. I tried many code with no success.

I don’t understand why all the getRowCount() and similar doesn’t work.

Thanks

Hello,
Your request is unclear. You should specify the database ( such as HSQLDB etc) and LO version used as well as your OS.
.
You are not noting what result you expect - some kind of total? If so why not a query?
.
More detail is necessary.

here is an example of chatgpt answer which looked ok but wasn’t :

Sub CountRowsInFormTable
    Dim oDoc As Object
    Dim oForm As Object
    Dim oTableControl As Object
    Dim oTable As Object
    Dim nRowCount As Integer
    
    ' Get the current document
    oDoc = ThisComponent
    
    ' Get the form that contains the table
    oForm = oDoc.DrawPage.Forms.getByName("MyForm")
    
    ' Get the control that represents the table in the form
    oTableControl = oForm.getByName("MyTableControl")
    
    ' Get the table object from the control's model
    oTable = oTableControl.Model
    
    ' Get the number of rows in the table
    nRowCount = oTable.Rows.Count
    
    ' Display the number of rows in a message box
    MsgBox "The table has " & nRowCount & " rows."
End Sub

With this exemple the error is property or method not find “.Model”

After a night i realised i could do another way. execute a select to produce an array and iterate over this array.

At this time i don’t have worked since my last question.

A big problem for me with libre office is to find a clear documentation of the basic language…

Thanks a lot for your answers.

@Jonathan35
Here is some documentation which should be of help → https://docs.oracle.com/cd/E19064-01/so7/817-1826/817-1826.pdf
.
For a sample of select in a macro see → Executing SQL Statements from Forms with macros - #2 by Ratslinger

Don’t search for the “basic language”. Programming can be done with BASIC, Python, JavaScript, as well as C++, C# Java. You need to find the proper functions of the API, named UNO for LibreOffice or OpenOffice.
.
A starting document may be (mostly BASIC):
https://www.pitonyak.org/oo.php

A table control has no data (no records) to iterate over. The elements of a table control are text boxes, numeric controls, date controls, time controls, check boxes, one box per column. The embedding table control shows multiple instances (one per row) of the embedded form controls.

If you are interested in data, you should iterate over the underlying form’s record set rather than the visual representation.

There may be millions or billions of records in a record set. A Base form loads the first block only, enough to fil the user interface. This is indicated by the asterisk behind the row number. When you navigate to the last record, the row count is shown without asterisk.
SELECT COUNT(*) AS "C" FROM "record set" queries the rows count of a record set.

I can’t iterate over my table control. I tried many code with no success.
I don’t understand why all the getRowCount() and similar doesn’t work.

Base Form documents use the Model-View paradigm.

The View knows how to display data but knows nothing about the data source. On the other side the Model knows all about the data and its source but nothing about how to display it.

Form controls are on the View side so they can only access records the Model presents them. Controls have none of the data access functions such as getRowCount().

A way to visualize at it, if you open the Base Form Navigator it displays a tree structure of Forms and SubForms (Model) and under each Form are the Controls (View).