Hello, I ran into an issue where after deleting a row in the table, an error appears in the total amount and the reason is that after deleting a row, one of the rows appears with a value of null and this issue appears if the table contains more than one page
Here is the attached file.
Attached is an example of b4j and b4a and the issue appears on both platforms
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private B4XTable1 As B4XTable
Private RowsDeleted As Int
End Sub
B4X:
Sub DeleteRow (tbl As B4XTable, RowId As Long)
tbl.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))
tbl.ClearDataView 'Updates the rows count.
RowsDeleted = RowsDeleted + 1
End Sub
B4X:
Private Sub CalculateTotalColumnB4XTable1(Column As String) As Double
Try
Dim Total As Double = 0
For i = 1 To B4XTable1.Size + RowsDeleted
Dim row As Map = B4XTable1.GetRow(i)
Log($"${i} : ${row}"$ )
If row.Size > 0 Then
Dim value As Double = row.Get(Column)
Total = Total + value
End If
Next
Log("Total of column 0: " & Total)
xui.MsgboxAsync(Total, "Total of column 0: ")
Catch
Log(LastException)
xui.MsgboxAsync(LastException, "LastException")
End Try
Return Total
End Sub
Thank you very much
The total works, but the error is still there.
It's visible when you print.
One of the undeleted columns shows a null value
See the screenshot and you can try
Here is the example with the printing form
Thank you very much
The total works, but the error is still there.
It's visible when you print.
One of the undeleted columns shows a null value
See the screenshot and you can try
Here is the example with the printing form
It's same.
Loop the values.
If the map has zero items, don't include it.
B4X:
For i = 1 To Table.Size
Dim row As Map = B4XTable1.GetRow(i)
If row.Size > 0 Then
For Each Column As B4XTableColumn In Table.Columns
PrintString = PrintString & "<tr>"
PrintString = PrintString & $"<td>${row.Get(Column.Title)}</td>${CRLF}"$
PrintString = PrintString & "</tr>"
Next
End If
Next
It's same.
Loop the values.
If the map has zero items, don't include it.
B4X:
For i = 1 To Table.Size
Dim row As Map = B4XTable1.GetRow(i)
If row.Size > 0 Then
For Each Column As B4XTableColumn In Table.Columns
PrintString = PrintString & "<tr>"
PrintString = PrintString & $"<td>${row.Get(Column.Title)}</td>${CRLF}"$
PrintString = PrintString & "</tr>"
Next
End If
Next
For i = 1 To B4XTable1.Size + RowsDeleted
Dim row As Map = B4XTable1.GetRow(i)
If row.Size > 0 Then
For Each Column As B4XTableColumn In Table.Columns
PrintString = PrintString & "<tr>"
PrintString = PrintString & $"<td>${row.Get(Column.Title)}</td>${CRLF}"$
PrintString = PrintString & "</tr>"
Next
End If
Thank you very much aeric
The solution was close
But I went too far