I have a 2D array which contains integers and strings.I need to remove duplicate entries from it.Plz help
remove duplicates from a 2D arrayI need to remove duplicate entries from a 2D array.
Page 1 of 1
6 Replies - 5271 Views - Last Post: 01 October 2008 - 03:17 AM
Replies To: remove duplicates from a 2D array
#2
Re: remove duplicates from a 2D array
Posted 30 September 2008 - 09:11 PM
[rules][/rules]
#3
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
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
#4
Re: remove duplicates from a 2D array
Posted 30 September 2008 - 11:20 PM
Is it vb.net???
[in vb6]use two loops.
[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
#5
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
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
#6
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
i think using a string variable for the array is more effective because it can store both numbers and strings
#7
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
how can you hadle a array as single and musti dimension in a same function its just raise the compile time error
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|