|
-
Sep 29th, 2003, 06:18 PM
#1
Thread Starter
Lively Member
Array Help
I have two arrays both holding people's names, i.e.
Array 1
James
Adam
Craig
Bob
Joe
Array 2
James
Adam
Susan
Stephen
Ruby
What I want to do is that is search through Array 1 and Array 2 and if the same name appears in
Array 1 and Array 2 then delete it from Array 1. With the names above you would finish up with:
Array 1
Craig
Bob
Joe
Array 2
James
Adam
Susan
Stephen
Ruby
Can someone assist me with this please?
-
Sep 29th, 2003, 06:32 PM
#2
This is a place to start, you will need to improve the Array1 reloading!:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim sArr1(5) As String, sArr2(5) As String
Dim i As Long, x As Long
'Load Arrays
sArr1(0) = "James"
sArr1(1) = "Adam"
sArr1(2) = "Craig"
sArr1(3) = "Bob"
sArr1(4) = "Joe"
sArr2(0) = "James"
sArr2(1) = "Adam"
sArr2(2) = "Susan"
sArr2(3) = "Stephen"
sArr2(4) = "Ruby"
'Perform Check, and delete as nesessary
For i = 0 To UBound(sArr1)
For x = 0 To UBound(sArr2)
If LCase(sArr1(i)) = LCase(sArr2(x)) Then sArr1(i) = ""
Next
Next
'Display the result
MsgBox Join(sArr1, vbCrLf)
End Sub
Bruce.
-
Sep 29th, 2003, 06:40 PM
#3
I would suggest using collections :
VB Code:
Private Sub Form_Load()
Dim Col1 As New Collection
Dim Col2 As New Collection
Col1.Add "James"
Col1.Add "Adam"
Col1.Add "Craig"
Col1.Add "Bob"
Col1.Add "Joe"
Col2.Add "James"
Col2.Add "Adam"
Col2.Add "Susan"
Col2.Add "Stephen"
Col2.Add "Ruby"
Dim i As Integer
Dim j As Integer
On Error Resume Next
For i = 1 To Col1.Count
For j = 1 To Col2.Count
If LCase(Col1.Item(i)) = LCase(Col2.Item(j)) Then
Col1.Remove i
End If
Next
Next
On Error GoTo 0
For i = 0 To Col1.Count
MsgBox Col1.Item(i)
Next
End Sub
Has someone helped you? Then you can Rate their helpful post. 
-
Sep 29th, 2003, 06:45 PM
#4
Originally posted by manavo11
I would suggest using collections :
Well..... My guess is its an assignment on ARRAYS
-
Sep 29th, 2003, 06:53 PM
#5
-
Sep 29th, 2003, 06:56 PM
#6
Originally posted by manavo11
The problem (just something annoying) is that it doesn't remove the entries, it makes them equal to "". So you still get an empty line.
Yep, your right, I mentioned that in my post that additional work is required.
And, valid point re the Collection (and no 'blanks').
Bruce.
-
Sep 29th, 2003, 07:06 PM
#7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|