# Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
 It is currently Wed Feb 26, 2020 8:52 am

 All times are UTC - 5 hours

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Finding Duplicate Rows with ListboxPosted: Sat Apr 17, 2010 11:21 am

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 jNext i`

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

Top

 Post subject: Re: Finding Duplicate Rows with ListboxPosted: Sat Apr 17, 2010 2:09 pm

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 booleandim list as stringdim rowcount as integerfound = falserowcount = Listbox1.ListCount-1For 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 ifNext jNext iif found thenmsgbox list  //or print t a file or whateverend 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

 Post subject: Re: Finding Duplicate Rows with ListboxPosted: Sat Apr 17, 2010 2:22 pm

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
--------------------------------------------------
Watch out for European spammers who try to sell plug-ins you don't even need.

Top

 Post subject: Re: Finding Duplicate Rows with ListboxPosted: Tue May 17, 2011 7:59 pm

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

 Post subject: Re: Finding Duplicate Rows with ListboxPosted: Wed May 18, 2011 1:23 pm

Joined: Fri Jun 05, 2009 11:50 am
Posts: 348
Location: Hamburg, Germany

`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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC - 5 hours

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

Search for:
 Jump to:  Select a forum ------------------ General    General    Getting Started    Networking    Databases    Visual Basic to REAL Studio Conversion    Games    Plugins    Tips    Web Control SDK Platform Specific    Windows    Macintosh    Linux    Web Other Topics    Announcements    Off-Topic    Third Party Add-ons