B4A Library [Class] Flexible Table

vbmundo

Well-Known Member
Licensed User
Look



1st Row readed . Data[0] is filled with Row[0]
2nd Row readed. Data[0] and Data[1] is filled with Row[1]
3rd Row readed. Data[0] and Data[1] and Data[2] is filled with Row[2]

Is not a CLICK EVENT issue... CLICK EVENT only retrieve info from DATA list... but DATA list is bad filled.
 

vbmundo

Well-Known Member
Licensed User
Hi Klaus

Your video doesn't fix my issue.

I Put your class and I didn't and I did touch any single character of your class.

I sent to you a single debuging video.. you can see that DATA list have fails...

I don't know what to do..

Thanks
 

klaus

Expert
Licensed User
Longtime User
I have vbmundos' code, but I cannot test it because he uses a payed library I don't have.
I made a test program filling the table the same way he does, and in this program the filling and the table works.
But I am afraid that he didn't' even try this test program, my goal is trying to find where the problem is.
 

vbmundo

Well-Known Member
Licensed User
Maybe the problem is not the class; instead it could be the way you fill the table with data.

Please post the code which fills the table.

This is the CODE

B4X:
Sub TablesSQL_Result(data As List, meta As Map)
    Dim m As Map, i As Int
    Dim mm As Map
  
    Try
        If data.Size=0 Then
            Msgbox("your query returned no results","No Data")
            Activity.Finish
        End If
        m.Initialize
        m=data.Get(0)
        Dim Campos(m.size) As String
        Dim Cabeceras(m.Size) As String
  
        ' Formateo Tabla
  
        g.Initialize(Me,"g")
        g.InitializeTable(m.size,0,False)
        g.AddToActivity(Activity , 0, 50dip, 100%x, 80%y)

        For i=0 To m.Size-1
            Cabeceras(i)=m.GetKeyAt(i)
        Next
        G.SetHeader(Cabeceras)
  
        ' Leo Registros
  
        For i = 0 To data.Size-1
            mm=data.Get(i)
            Log(mm.GetValueAt(0))
            For ii = 0 To mm.Size-1
                Campos(ii)=mm.GetValueAt(ii)
            Next
            G.AddRowAutomaticWidth(Campos)
        Next
           ProgressDialogHide
        lblCantRegistros.Text=data.size & " Rows "
      
    Catch
        Log(LastException)
        If LastException.Message.Contains("Java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0")=True Then
            Msgbox("Your Query has not return any row. Remember that Empty Date Fields '0000-00-00' not return Null Dates. You must Include a Conversion into your SQL Stattement","Help")
        End If
        Msgbox("An Error has occurred. " & LastException.Message ,"Error")
    End Try
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
This is the CODE
Try this code. I´ve move the DIM of the inner Maps so that there is always created a new map instead of reusing the old one.

B4X:
Sub TablesSQL_Result(data As List, meta As Map)
    Try
        If data.Size=0 Then
            Msgbox("your query returned no results","No Data")
            Activity.Finish
        End If
        Dim m As Map
                m.Initialize
        m=data.Get(0)
        Dim Campos(m.size) As String
        Dim Cabeceras(m.Size) As String
 
        ' Formateo Tabla
 
        g.Initialize(Me,"g")
        g.InitializeTable(m.size,0,False)
        g.AddToActivity(Activity , 0, 50dip, 100%x, 80%y)

        For i=0 To m.Size-1
            Cabeceras(i)=m.GetKeyAt(i)
        Next
        G.SetHeader(Cabeceras)
 
        ' Leo Registros
 
        For i = 0 To data.Size-1
            Dim mm As Map
            mm.Initialize
                        mm=data.Get(i)
            Log(mm.GetValueAt(0))
            For ii = 0 To mm.Size-1
                Campos(ii)=mm.GetValueAt(ii)
            Next
            G.AddRowAutomaticWidth(Campos)
        Next
           ProgressDialogHide
        lblCantRegistros.Text=data.size & " Rows "
     
    Catch
        Log(LastException)
        If LastException.Message.Contains("Java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0")=True Then
            Msgbox("Your Query has not return any row. Remember that Empty Date Fields '0000-00-00' not return Null Dates. You must Include a Conversion into your SQL Stattement","Help")
        End If
        Msgbox("An Error has occurred. " & LastException.Message ,"Error")
    End Try
End Sub
 

klaus

Expert
Licensed User
Longtime User
This code works:
B4X:
Sub TablesSQL_Result(data As List, meta As Map)
    Dim m As Map, i As Int
    Dim mm As Map

    Try
        If data.Size=0 Then
            Msgbox("your query returned no results","No Data")
            Activity.Finish
        End If
        m.Initialize
        m=data.Get(0)
'       Dim Campos(m.size) As String
        Dim Cabeceras(m.Size) As String

        ' Formateo Tabla

        g.Initialize(Me,"g")
        g.InitializeTable(m.size,0,False)
        g.AddToActivity(Activity , 0, 50dip, 100%x, 80%y)

        For i=0 To m.Size-1
            Cabeceras(i)=m.GetKeyAt(i)
        Next
        G.SetHeader(Cabeceras)

        ' Leo Registros

        For i = 0 To data.Size-1
            mm=data.Get(i)
            Log(mm.GetValueAt(0))
            Dim Campos(m.size) As String
            For ii = 0 To mm.Size-1
                Campos(ii)=mm.GetValueAt(ii)
            Next
            G.AddRowAutomaticWidth(Campos)
        Next
           ProgressDialogHide
        lblCantRegistros.Text=data.size & " Rows "
   
    Catch
        Log(LastException)
        If LastException.Message.Contains("Java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0")=True Then
            Msgbox("Your Query has not return any row. Remember that Empty Date Fields '0000-00-00' not return Null Dates. You must Include a Conversion into your SQL Stattement","Help")
        End If
        Msgbox("An Error has occurred. " & LastException.Message ,"Error")
    End Try
End Sub
You must move Dim Campos(m.size) As String into the For i = 0 To data.Size-1 loop !

So the problem was NOT in the Flexible Table Class !

My thanks go to DonManfred for having sent me his library to be able to test the program.
I hope that this example shows why I always ask for the code to be able to test it!
 

DonManfred

Expert
Licensed User
Longtime User
You must move Dim Campos(m.size) As String into the For i = 0 To data.Size-1 loop
dammit. I oversee this one But i did not test my code. I just edited the code here in the editor.

My thanks go to DonManfred for having sent me his library to be able to test the program.
You´re welcome
 

vbmundo

Well-Known Member
Licensed User

I will try. but I don't understand... I debug line by line. and the DATA list is filled with the right data... you can see the value during Debug.

But, I will try and response.

Thanks
 

vbmundo

Well-Known Member
Licensed User
B4X:
        For i = 0 To data.Size-1
            Dim mm As Map
            mm.Initialize
                        mm=data.Get(i)
            Log(mm.GetValueAt(0))
            For ii = 0 To mm.Size-1
                Campos(ii)=mm.GetValueAt(ii)
            Next
            G.AddRowAutomaticWidth(Campos)
        Next

Why you think that this code have problems ?

CAMPOS have allways the same SIZE...

The SQL Stattement return rows... all rows have the same number of columns.

CAMPOS is replaced on every FOR NEXT with new values...

I don't undestand why you must to DEFINE with DIM on every FOR NEXT .. this for me is a bad practice

Can you explain Why a MAP that have 5 elements, need to be redefined again if the new values have 5 elements ?

I don't undestand your logical solution.
 

vbmundo

Well-Known Member
Licensed User
Try this code. I´ve move the DIM of the inner Maps so that there is always created a new map instead of reusing the old one.

Hi DonManfred

when you create a vector You can move values again and again .. you do not create every time that you need to moving him again new values.

I do not understand why a MAP should do so.

Thanks
 

vbmundo

Well-Known Member
Licensed User
Now works...

It's impossible... this have not Logical.

You need to DIM an array every time that you need to use ?

If you DIM an Array with 10 elements, and now move "xxxx" to Array(0) and then move "yyyyy" to Array(0) you have the same Array with new values...

It's crazy...

Thanks for all
 

vbmundo

Well-Known Member
Licensed User
Try this code. I´ve move the DIM of the inner Maps so that there is always created a new map instead of reusing the old one.

Yes.. your recommendation and the Klaus works.

But now...

Might explain this unexplainable sounds sincerely?

It's crazy..

CAMPOS is just an ARRAY .. and as far as I know, and my more than 26-year career, you have not redefine an array to simply move him new values.

It's crazy that escapes all logic ..

I spent 15 days trapped in this bug because I did not use Irrational idea of putting a DIM within a FOR ..

I know half a dozen programming languages and never saw anything so crazy.

I apologize if I upset with something, but I had really put a goal in time and I was overcome ..

Thank you for all.. I have now 2 of the best B4A controls.. your MySQL Control and the Klaus Table.

Regards
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…