Comparing 2 Lists
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 10
- Joined: Fri Apr 30, 2010 3:10 pm
Comparing 2 Lists
I am trying to compare two lists that are found in two text files. I have been using Readln to read through the files but am having trouble coming up with a way to compare it against another list and tell me which numbers in the lists do not match up to each other. The lists look something like this:
List one:
0021545
0021584
0023625
0036584
0014793...
List Two:
0021545
0021585
0023625
0036584
0014793...
I am trying to create a macro that can tell me that number in red from list one is not in list two and that the number in red from list 2 is not in list one.
I am just having trouble visualizing the solution.
List one:
0021545
0021584
0023625
0036584
0014793...
List Two:
0021545
0021585
0023625
0036584
0014793...
I am trying to create a macro that can tell me that number in red from list one is not in list two and that the number in red from list 2 is not in list one.
I am just having trouble visualizing the solution.
compare lists with fc (file compare)
Is order significant in comparing the lists?
Are the lists in sorted order to begin with?
Try running the DOS command FC on the two text files
and examining the output
Is this similar to what you are looking for?
i.e.
C:\>fc list1.txt list2.txt
Are the lists in sorted order to begin with?
Try running the DOS command FC on the two text files
and examining the output
Is this similar to what you are looking for?
i.e.
C:\>fc list1.txt list2.txt
-
- Newbie
- Posts: 10
- Joined: Fri Apr 30, 2010 3:10 pm
-
- Newbie
- Posts: 10
- Joined: Fri Apr 30, 2010 3:10 pm
It seems as if the DOS command goes through the lists 1 line at a time and compares line one to line 1 etc. It was also including other lines before and after the mismatched lines which was getting quite confusing. It looks like it is in the right direction but not exactly what I am looking for yet.
There is a way to do it in excel using conditional formatting which works fine but takes time copying the lists into an excel file etc. I am sure there is a way for Macro Scheduler to do it but I just cant pinpoint the solution!!
There is a way to do it in excel using conditional formatting which works fine but takes time copying the lists into an excel file etc. I am sure there is a way for Macro Scheduler to do it but I just cant pinpoint the solution!!
-
- Newbie
- Posts: 10
- Joined: Fri Apr 30, 2010 3:10 pm
Try reading in the lists to an array.
Then create a subroutine which loops through
every array item looking for a match with the
passed in parameter.
The main logic would be:
1. Read each line in list1 (at EOF quit)
2. execute the subroutine looking for that number in array2 (list2)
3. If it doesn't exist, make a note of it
4. Go back to step 1
Do the same logic again, but this time read list2 looking
in the array1 (list1) for mis-matches.
Then create a subroutine which loops through
every array item looking for a match with the
passed in parameter.
The main logic would be:
1. Read each line in list1 (at EOF quit)
2. execute the subroutine looking for that number in array2 (list2)
3. If it doesn't exist, make a note of it
4. Go back to step 1
Do the same logic again, but this time read list2 looking
in the array1 (list1) for mis-matches.
-
- Newbie
- Posts: 10
- Joined: Fri Apr 30, 2010 3:10 pm
-
- Newbie
- Posts: 10
- Joined: Fri Apr 30, 2010 3:10 pm
ReadFile>C:\Users\Preferred User\Desktop\List1.txt,List1
Separate>List1,CR,Array1
ReadFile>C:\Users\Preferred User\Desktop\List2.txt,List2
Separate>List2,CR,Array2
Messagemodal>Array1_count
if>Array1_count=0,End
Let>k=0
Repeat>k
Label>Continue
Let>k=k+1
MessageModal>Array1_%k%
Gosub>Search
If>Array1_%k%=,End
Until>k=Array1_count
Label>End
SRT>Search
if>Array2_count=0,End
Let>x=0
Repeat>x
Let>x=x+1
If>Array2_%x%=Array1_%k%
Goto>Continue
Else
goto>searchmore
EndIF
Label>searchmore
Until>x,Array2_count
Let>A1=Array1_%k%
MessageModal>%A1% not found in list 2
END>Search
This is what I have come up with thus far. It is working just as I would like but for some reason it continues the loop forever instead of ending at Array1_count....I can't figure out why it won't stop but I am sure it is some simple mistake in the loops....
Separate>List1,CR,Array1
ReadFile>C:\Users\Preferred User\Desktop\List2.txt,List2
Separate>List2,CR,Array2
Messagemodal>Array1_count
if>Array1_count=0,End
Let>k=0
Repeat>k
Label>Continue
Let>k=k+1
MessageModal>Array1_%k%
Gosub>Search
If>Array1_%k%=,End
Until>k=Array1_count
Label>End
SRT>Search
if>Array2_count=0,End
Let>x=0
Repeat>x
Let>x=x+1
If>Array2_%x%=Array1_%k%
Goto>Continue
Else
goto>searchmore
EndIF
Label>searchmore
Until>x,Array2_count
Let>A1=Array1_%k%
MessageModal>%A1% not found in list 2
END>Search
This is what I have come up with thus far. It is working just as I would like but for some reason it continues the loop forever instead of ending at Array1_count....I can't figure out why it won't stop but I am sure it is some simple mistake in the loops....
search arrays for items in list
Try This. I think it is bad programming practice to use Goto to jump outside of a subroutine. Better to let the subroutine end and then test to see what happened after the code resumes after the Gosub.
I also think you needed to use a delimiter of CRLF instead of just CR.
[code]
ReadFile>C:\List1.txt,List1
Separate>List1,CRLF,Array1
ReadFile>C:\List2.txt,List2
Separate>List2,CRLF,Array2
Messagemodal>Array1_count
if>Array1_count=0,End
if>Array2_count=0,End
Let>k=0
Repeat>k
Let>k=k+1
MessageModal>Array1_%k%
Gosub>Search
If>Found=False
Let>A1=Array1_%k%
MessageModal>%A1% not found in list 2
Endif
Until>k=Array1_count
Label>End
SRT>Search
Let>Found=False
Let>x=0
Repeat>x
Let>x=x+1
If>Array2_%x%=Array1_%k%
Let>Found=True
Goto>Search_x
EndIF
Until>x,Array2_count
Label>Search_x
END>Search
[/code]
I also think you needed to use a delimiter of CRLF instead of just CR.
[code]
ReadFile>C:\List1.txt,List1
Separate>List1,CRLF,Array1
ReadFile>C:\List2.txt,List2
Separate>List2,CRLF,Array2
Messagemodal>Array1_count
if>Array1_count=0,End
if>Array2_count=0,End
Let>k=0
Repeat>k
Let>k=k+1
MessageModal>Array1_%k%
Gosub>Search
If>Found=False
Let>A1=Array1_%k%
MessageModal>%A1% not found in list 2
Endif
Until>k=Array1_count
Label>End
SRT>Search
Let>Found=False
Let>x=0
Repeat>x
Let>x=x+1
If>Array2_%x%=Array1_%k%
Let>Found=True
Goto>Search_x
EndIF
Until>x,Array2_count
Label>Search_x
END>Search
[/code]
-
- Newbie
- Posts: 10
- Joined: Fri Apr 30, 2010 3:10 pm