Following are the some of color codes
Monday, 1 January 2018
Issues on multiple Row Deletion using FOR Loop.
While deleting multiple rows in a datawindow, you cannot simply use a For..Next statement loop from top to bottom as when you delete a row, the rowcount is changed.
Following will throw an Error
Long ll_RowCount, ll_Start
ll_RowCount = dw_1.rowcount()
For ll_Start = 1 to ll_RowCount
if dw_1.getitemstring(ll_Start,'Status') = 'D' then
dw_1.deleterow()
end if
Next
The correct script should like the follow.
Example1:
For ll_Start = 1 to dw_1.rowcount()
if dw_1.getitemstring(ll_Start,'Status') = 'D' then
dw_1.deleterow()
ll_Start-- // adjust pointer
end if
Next
Example2: On Reverse Order
ll_RowCount = dw_1.rowcount()
For ll_Start = ll_RowCount to 1 step -1
if dw_1.getitemstring(ll_Start,'flag') = 'D' then
dw_1.deleterow()
end if
Next
Following will throw an Error
Long ll_RowCount, ll_Start
ll_RowCount = dw_1.rowcount()
For ll_Start = 1 to ll_RowCount
if dw_1.getitemstring(ll_Start,'Status') = 'D' then
dw_1.deleterow()
end if
Next
The correct script should like the follow.
Example1:
For ll_Start = 1 to dw_1.rowcount()
if dw_1.getitemstring(ll_Start,'Status') = 'D' then
dw_1.deleterow()
ll_Start-- // adjust pointer
end if
Next
Example2: On Reverse Order
ll_RowCount = dw_1.rowcount()
For ll_Start = ll_RowCount to 1 step -1
if dw_1.getitemstring(ll_Start,'flag') = 'D' then
dw_1.deleterow()
end if
Next
Subscribe to:
Posts (Atom)