01-01-2008, 05:32 AM
he is an example of the first column of my mshflexgrid
i want to delete the records (only in mshflexgrid) based on the occurrence of ID in the above column....say, i want to delete all ID which have occurred less than three times...so that i would get data with ID 3 and 8 only... hope i m clear...any help will be greatly appreciated....
01-01-2008, 06:33 AM
The FlexGrid only displays the data.
If you want to remove some of the data you have to come up with some algoritm to do so.
There is no magical trick.
In the case of having only items shown which occur at least 3 times, you have to loop through all records, count the number of occurences for each ID the walk through the grid (bottom to top) and remove those lines which don't match your criteria.
01-01-2008, 11:52 PM
I apologise for how confusing this code is about to be. Maybe there is a better solution but this is the best i can think of
'Delete all items that occur less than 3 times
private sub DeleteItems()
'You need an array of integers
dim Occurences() as integer
dim x as integer
'Redim the array (if you dont then ubound() will fail)
'First loop through each row and count up how many times each number occurs
for x = 0 to FlexGrid.rows-1
'The number will be the index in the array
'Check if the rows number is bigger than the array's ubound()
'It is too big so you have to make the array bigger
'Use "redim preserve" instead of just "redim" so the data in the array wont be lost
redim preserve occurences(val(flexgrid.textmatrix(x,0)))
'Add 1 to the correct item in the array
'Now the occurences() array knows how many times each number was used
'You have to loop through again to delete the rows
'This row is slightly different. Remember we are deleting rows!
do while x<flexgrid.rows
'Check if the number of occurences of this rows number is less than 3
if occurences(val(flexgrid.textmatrix(x,0)))<3 then
'It is so delete the row
'If you dont delete the row then you have to move to the next one
Ive not tested it but that should work. For the second loop you can work backwards like Flyguy said instead
Edit: This is a very detailed example ;)
01-02-2008, 01:14 AM
Thats my question....being a newbie i m having very hard time to sort this out...
any rapid solution would be very helpful for me now...
This is NOT a code handout site.
You first have to show your own efforts.
I gave a hint how to approach this problem and you only start to beg :-\
01-02-2008, 03:29 AM
Sorry FLYGUY for being presenting myself in that way....(as being a new in VB, sometimes it is very difficult think of a logic when u are stucked somewhere.... )
Just going through the code of the master :D .... Thanx
01-02-2008, 06:16 AM
getting error "Expected Array" on the following line
if val(flexgrid.textmatrix(x,0))>ubound(occurences(0)) Then
01-02-2008, 06:31 AM
Woops. Thats a typo. The correct code is the following
if val(flexgrid.textmatrix(x,0))>ubound(occurences()) Then
01-03-2008, 12:05 AM
Worked.............Thanx for ur help....:D :D :D