Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Sep 21, 2019 4:39 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Finding Duplicate Rows with Listbox
PostPosted: Sat Apr 17, 2010 11:21 am 
Offline
User avatar

Joined: Sat Apr 04, 2009 5:10 pm
Posts: 954
Anyone can do it, but just in case...

For i=0 To Listbox1.ListCount-1
For j=0 To Listbox1.ListCount-1
If i=j Then
Else
If Listbox1.Cell(i,0)=Listbox1.Cell(j,0) Then
MsgBox "Row "+Str(i+1)+" and Row "+Str(j+1)+" are identical."
Exit Sub
End if
End if
Next j
Next i

_________________
Mac OS X 10.5.8/REALBasic 2008 R5.1 ~ REALBasic 2009 R4
--------------------------------------------------
Please don't use my topics in order to advertise your plug-ins.
Watch out for European spammers who try to sell plug-ins you don't even need.


Top
 Profile  
Reply with quote  
 Post subject: Re: Finding Duplicate Rows with Listbox
PostPosted: Sat Apr 17, 2010 2:09 pm 
Offline
User avatar

Joined: Fri Jun 05, 2009 11:50 am
Posts: 348
Location: Hamburg, Germany
That code would compare a lot of lines twice.

First loop of i would compare
e.g. Row 1 to Row 2 and then row 1 to row 3 and so on.

In the second loop it would compare

row 2 to row 1 (that comparisson already took place) and the row 2 to row 3 and so on.

The longer the list box is, the more double comparissons will take place

Also there will be only one identical line found. What, if there are more identical lines?

Edit: And do not count rows over and over again

Optimized would be something like

dim found as boolean
dim list as string
dim rowcount as integer
found = false

rowcount = Listbox1.ListCount-1

For i=0 To rowcount
For j=i+1 To rowcount
If Listbox1.Cell(i,0)=Listbox1.Cell(j,0) Then
list = list + "Row "+Str(i+1)+" and Row "+Str(j+1)+" are identical."+endofline
found = true
End if
End if
Next j
Next i

if found then
msgbox list //or print t a file or whatever
end if

_________________
Best regards

Stefan

Mac OSX Mountain Lion (latest Release) on a MacBook Pro 2.66 GHz Intel Core i7/ RB Professional 2011 Release 3


Last edited by elChupete on Sun Apr 18, 2010 9:29 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Finding Duplicate Rows with Listbox
PostPosted: Sat Apr 17, 2010 2:22 pm 
Offline
User avatar

Joined: Sat Apr 04, 2009 5:10 pm
Posts: 954
That's true. Thanks. For me, it doesn't matter, though.

_________________
Mac OS X 10.5.8/REALBasic 2008 R5.1 ~ REALBasic 2009 R4
--------------------------------------------------
Please don't use my topics in order to advertise your plug-ins.
Watch out for European spammers who try to sell plug-ins you don't even need.


Top
 Profile  
Reply with quote  
 Post subject: Re: Finding Duplicate Rows with Listbox
PostPosted: Tue May 17, 2011 7:59 pm 
Offline

Joined: Mon Sep 27, 2010 3:43 pm
Posts: 7
Location: Bass Lake, near Orillia,Ontario, Canada
very cagey.
ingenious.
I appreciate the idea, but want to go another step--REMOVE one (or more)of the duplicates..ie reduce the listbox to single instances of entries..
Any ideas??

_________________
ole George...


Top
 Profile  
Reply with quote  
 Post subject: Re: Finding Duplicate Rows with Listbox
PostPosted: Wed May 18, 2011 1:23 pm 
Offline
User avatar

Joined: Fri Jun 05, 2009 11:50 am
Posts: 348
Location: Hamburg, Germany
after (or instead of)

list = list + "Row "+Str(i+1)+" and Row "+Str(j+1)+" are identical."+endofline



store either i+1 or j+1 in an array (Important not both)

After loop has ended intstead of showing the messages box, delete the rows stored in the array.

Start with the highest (i.e. the last) row found. That means if the array consist of 2,4,5,12,23 delet row 23 first, then 12, 5 ... and so on.

If you would delete row 2 at first, the rownumbers of the following lines would become incorrect and you would delete the wrong lines.

I would prompt the row to be deleted to the user first and ask if those rows should be deleted

_________________
Best regards

Stefan

Mac OSX Mountain Lion (latest Release) on a MacBook Pro 2.66 GHz Intel Core i7/ RB Professional 2011 Release 3


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group