MatchMerge merges two text files in alpha
text sequence and optionally saves the merged records in a new file.
Text case is ignored, Options are provided to sort
input files if they are not in sequence, and to eliminate duplicate
records in the output file.
Background & Techniques
This started as a Beginners exercise in response to a user request but along the
way a need for a more complete program arose. A problem with
the December DFF Newsletter required me to delete the subscribers list
(after downloading a copy). Since then about 25 new users have
subscribed which needed to be combined with the original list before the next
newsletter can be sent. This program has merged the lists and
as a side benefit, eliminated a number of duplicate subscribed email
addresses - those who hit the "Subscribe" button twice
"just to be sure".
Non-programmers are welcome to read on, but may
want to skip to the bottom of this page to
download executable version of the program.
The merge logic uses an "GetNext"
function to return the lowest record which has not yet been returned to the
user for each call. The returned integer value is "1" or
"2" to indicate the source of the record (File1 or File2) or
"0" to indicate that all records have been returned.
Global variables "Line1" and
"Line2" are as look-ahead buffers to used hold the
next records to be compared from File1 and File2. They are
initialized with the first record from each file before the first call to GetNext.
When the Merge button is clicked, two file names
are solicited from the user. Procedure Checkfile
is called with each filename. Checkfile makes sure that the
records in the file are in ascending sequence or asks the user for
permission to sort the records if not. The program will
run with unsorted files, but results will generally be
The main processing loops calls the GetNext
to get the next record until the return value is 0. Each
record is checked to see if it matches the last record added to the output
display (Listbox3). If so it is counted as a duplicate and
either dropped or added to the list depending on whether the DupsBox
checkbox is checked. After all records have been
processed, the user is asked for an output file name and list box contents
written to the file if a name was provided.
Running/Exploring the Program