remove duplicates from a 2D array

I need to remove duplicate entries from a 2D array.

Page 1 of 1

6 Replies - 6492 Views - Last Post: 01 October 2008 - 03:17 AM Rate Topic: -----

#1 milirose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-September 08

remove duplicates from a 2D array

Post icon  Posted 30 September 2008 - 09:05 PM

I have a 2D array which contains integers and strings.I need to remove duplicate entries from it.Plz help
Is This A Good Question/Topic? 0
  • +

Replies To: remove duplicates from a 2D array

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: remove duplicates from a 2D array

Posted 30 September 2008 - 09:11 PM

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 milirose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-September 08

Re: remove duplicates from a 2D array

Posted 30 September 2008 - 09:29 PM

I have a function to Sort the array.
But before that I need to remove the duplicates from the array.
'Function to sort
Public Function SortArray(aArray As Variant, _
Optional ByVal iDimensions As Integer = 1, _
Optional ByVal iSortColumn As Integer = 1, _
Optional ByVal bAsc As Boolean = True, _
Optional ByVal IsCaseInsensitive = False) As Variant
' SORTS THE CONTENTS OF AN ARRAY - ASCENDING / DESCENDING DEPENDING ON bAsc VALUE
Dim i, j As Integer
Dim vCurr, vNext, vTemp As Variant
Select Case iDimensions
Case 1
' FOR A 1-D ARRAY
For i = UBound(aArray) - 1 To 0 Step -1
For j = 0 To i
If CompareSortValues(aArray(j), aArray(j + 1), bAsc, IsCaseInsensitive) Then
vTemp = aArray(j + 1)
aArray(j + 1) = aArray(j)
aArray(j) = vTemp
End If
Next j
Next i
Case 2
' FOR A 2-D ARRAY
ReDim vNext(UBound(aArray, 2))
ReDim vCurr(UBound(aArray, 2))
For i = UBound(aArray) - 1 To 0 Step -1
For j = 0 To i
If CompareSortValues(aArray(j, iSortColumn), aArray(j + 1, iSortColumn), bAsc, IsCaseInsensitive) Then
vNext = GetArrayRow(aArray, j + 1)
vCurr = GetArrayRow(aArray, j)
' REORDER THE ARRAY ROWS
aArray = ReplaceArrayRow(vCurr, aArray, j + 1)
aArray = ReplaceArrayRow(vNext, aArray, j)
End If
Next j
Next i
End Select
SortArray = aArray
End Function



'I dont want to include the duplicate removal in this function.I need it as a general function
Was This Post Helpful? 0
  • +
  • -

#4 akhileshbc  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 179
  • Joined: 27-September 08

Re: remove duplicates from a 2D array

Posted 30 September 2008 - 11:20 PM

Is it vb.net???

[in vb6]use two loops.

for i=1 to 10
for j=i+1 to 10
if a[j]=a[i] then
msgbox "duplicate found"
'do your own coding to remove the duplicate in here
end if
next j
next i

Was This Post Helpful? 0
  • +
  • -

#5 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: remove duplicates from a 2D array

Posted 01 October 2008 - 02:50 AM

whether the duplicates are found in integers or in strings or in both

how can a array hold both string and integers (confusing.......)

give some sample data

This post has been edited by thava: 01 October 2008 - 02:55 AM

Was This Post Helpful? 0
  • +
  • -

#6 akhileshbc  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 179
  • Joined: 27-September 08

Re: remove duplicates from a 2D array

Posted 01 October 2008 - 02:59 AM

@thava, he is using a variant for the array :)
i think using a string variable for the array is more effective because it can store both numbers and strings
Was This Post Helpful? 0
  • +
  • -

#7 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: remove duplicates from a 2D array

Posted 01 October 2008 - 03:17 AM

i dont think this function works correctly

how can you hadle a array as single and musti dimension in a same function its just raise the compile time error
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1