I’m trying to compare data between two list boxes and highlight text that differs between the two.
It works if each listbox has the same number of elements (rows). But I obviously get an OutOfBounds exception if they have different amount of items. How do I get around that?
I’ve tried storing the values of the cells in 2 separate arrays and that works fine, but then I don’t know how to make that connection back to the listbox to color the text when/if needed.
This is the code for the CellTextPaint event handler:
dim source as Listbox = lstbox1
dim destination as Listbox = lstbox2
if destination.Listcount >= 1 then
If source.Cell(row, -1) = destination.Cell(row, -1) Then
g.ForeColor = Color.Green
else
g.ForeColor = Color.Red
end if
End If
And here is a method I found for checking the elements of both arrays:
//contents of a() is listbox1 - contents of b() is listbox2
if ubound(a)=UBound(b) and (UBound(a)+UBound(b))>=0 then
dim i as integer
dim k as integer
dim ok as integer
ok=0
//ok counts how many times there are the same elements
for i=0 to ubound(a)
for k=0 to UBound(b)
if a(i)=b(k) then ok=ok +1
next
next
if ok>UBound(a) then
MsgBox("All of the files were successfully transfered.")
return true
else
//different dimensions
//or one of the 2 arrays is empty
MsgBox("Some files were not transferred.")
return false
end if
end if
I’m okay with going the route of the arrays as that seems to be the most efficient way, but again, I’m unsure of how to connect that back to the CellTextPaint handler.