[AccessD] Difference in strings

Stuart McLachlan stuart at lexacorp.com.pg
Fri Apr 18 18:53:30 CDT 2003


On 18 Apr 2003 at 15:48, Stoker, Kenneth E wrote:

> Everyone,
> 
> Is there a built-in function in VBA that will compare two strings and
> return the difference of the two?  I want to remove values from a
> listbox so I thought I could set one variable to the listbox rowsource
> and another variable to the listbox itemsselected and return the
> difference of the two.  If there is a built-in function, I would
> rather use that than create my own, but will if I have to.
> 
The problem with doing this sort of thing on strings is 
resynchronizing your two string position pointers after you come 
across the first difference.  

>From what you describe here, it looks as tough you are talking about 
complete items, not partial strings so *could* do as long as you used 
unique delimiters between the items - But you would be far better of 
treating the list items separately rather than trying to build 
strings containing all the items and then have to extract them again 
for comparison.

Actually, the simplest way I can see to do this doesn't use extras 
strings or arrays:

Dim loopcount As Long
Dim strNewList as sting

For loopcount = 0 To List2.ListCount
    If Not List2.Selected(loopcount) Then
        strNewList = strNewList & List2.ItemData(loopcount) & ";" 
    End If
Next
strNewList = Left$(strNewList, Len(strNewList) - 1)
List2.RowSource = strNewList


-- 
Lexacorp Ltd
http://www.lexacorp.com.pg
Information Technology Consultancy, Software Development,System 
Support.





More information about the AccessD mailing list