Table issue

tvrman

Member
Licensed User
Dear all,
after 3 years im trying again with Basic4pcc, i have an old project
which i need to rewrite.
starting up again, i facing the issue with tables, after filling up with
new data seems fine, but after table1.clear and fill up again the table
is not empty its add data the the current rows :confused::confused:
like i have 1940 files, after changing folder with 3 files, i have after clear
the table 1943 files in the table?
how can i solve.
thanks a lot.
 

sitajony

Active Member
Licensed User
You can use this code:
B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] i=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]To [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Table[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].RowCount-[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]    Table[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].RemoveRow(i)[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

;)
(Table is a Table control)
 

tvrman

Member
Licensed User
You can use this code:
B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] i=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]To [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Table[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].RowCount-[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]    Table[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].RemoveRow(i)[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

;)
(Table is a Table control)



Nice solution i tried, but after two times switching i says INDEX 970 is hoger than the row counts, before the message a mxgbox displays 1939 items,
really strange.
 

sitajony

Active Member
Licensed User
Nice solution i tried, but after two times switching i says INDEX 970 is hoger than the row counts, before the message a mxgbox displays 1939 items,
really strange.
Weird... I think that this bug come from Basic4PPC in 6.80 I've never viewed this error but now on 6.9 I've sometime this problem... Are you on 6.90?
 

agraham

Expert
Licensed User
Longtime User
Table.Clear should work without problems so I would check your code carefully and maybe post it here for us to look at at if it is not clearing properly.

The code that fails is trying to remove non-existent rows as the table is compacted after each remove. You could try

B4X:
For i=0 To Table.RowCount-1
    Table.RemoveRow([COLOR="Red"]0[/COLOR])
Next

or

B4X:
For i=o Table.RowCount-1 To 0 Step -1
    Table.RemoveRow(i)
Next
 

sitajony

Active Member
Licensed User
Table.Clear should work without problems so I would check your code carefully and maybe post it here for us to look at at if it is not clearing properly.

The code that fails is trying to remove non-existent rows as the table is compacted after each remove. You could try

B4X:
For i=0 To Table.RowCount-1
    Table.RemoveRow([COLOR=red]0[/COLOR])
Next

or

B4X:
For i=o Table.RowCount-1 To 0 Step -1
    Table.RemoveRow(i)
Next
I understand now why it return an error, because the index is removed so the count is reduced...
 

mjcoon

Well-Known Member
Licensed User
B4X:
For i=0 To Table.RowCount-1
    Table.RemoveRow([COLOR="Red"]0[/COLOR])
Next

I couldn't find any mention of it in the Help (when I first stumbled over it) but the end-value of a For ... To is only evaluated once at commencement. So the above gives you the full iteration and does not end too soon as the count decreases!

Mike.
 
Top