Sub CalcBal() As String
Dim column As B4XTableColumn = B4XTableM.GetColumn("paydate")
column.InternalSortMode= "ASC"
Dim rs As ResultSet = B4XTableM.sql1.ExecQuery("SELECT * FROM data ORDER BY [c0]")
Dim Bal As Double = rs.GetDouble("c10"),iBal As Int
Dim newAmt As Double
Do While rs.NextRow
If rs.GetString("c3").EndsWith ("CC") =False Then
newAmt=rs.GetDouble ("c9")
If newAmt=0 Then newAmt=rs.GetDouble("c7")
Bal=Bal+newAmt
End If
Log(rs.GetString("c5") & "-" & newAmt & "=" & Bal)
iBal =Bal
B4XTableM.sql1.ExecNonQuery2("UPDATE data SET [c10] = ? WHERE [c5] = ?", Array As String(iBal, rs.GetString("c5")))
Loop
rs.Close
B4XTableM.Refresh
End Sub