Re: TZF - Many Thanks but more help needed
Marie Vihonsky <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.topaz |
|---|---|
| Message-ID | <[email protected]> |
Hi Jerry,
Here's some code snippets (I use MDX's) written on the fly.
Index DB1 on firstname + lastname + phone (or address but remember the
max length for a key is 100 characters)
Const
DB1Tags: array[0..1] of TTagInfo = (
(name: 'NAME'; keyexpr: 'upper(firstname+lastname)+phone';
forexpr: ''; descending: FALSE; unique: FALSE),
(name: ''; keyexpr: ''; forexpr: '';
descending: FALSE; unique: FALSE));
Open the databases:
if not DB1.Active then begin
DB1.DbfFileName := pgmpath + 'DB1.dbf';
DB1.Exclusive := true;
DB1.Active := True;
DB1.MakeIndex(@DB1tags,'');
DB1.SetIndexTo('');
DB1.setordertotag('NAME');
DB1.gotop;
end;
if not DB2.Active then begin
DB2.DbfFileName := pgmpath + 'DB2.dbf';
DB2.Exclusive := true;
DB2.Active := True;
DB2.gotop;
end;
while not DB2.deof do begin
if not DB2.deleted then begin
key := upper(DB2.GetCField('first') + DB2.GetCField('last')) +
DB2.GetCField('phone');
if DB1.Find(key) then begin
DB2.SetCField('ID2') := DB1.GetCField('ID1');
DB2.ReplaceRec;
end
else begin
{your exception processing}
end;
end; {not deleted}
DB2.skip(1);
end;
Notice I'm NOT trimming any fields.
Hope this is enough to get you started,
Marie
Jerry Mallett wrote:
> Hi Marie
>
> Thanks for the response. It's taken me a while to get back to you. Got
> caught up in another project..just getting to the reponses now.
>
> OK, your idea is a good one but the problem is that we would have a lot of
> names the same. Here in Ireland we have 100's if not 1000's of
> McLaughlin's, Doherty's, Murphy's, etc so trying to match the names will not
> help.
>
> I would have to match the First and Last name's and there Street addresses
> or phone nos.
>
> I would be interested in that piece of code though.
>
> Many thanks
>
> Jerry
>
> ----- Original Message -----
> From: "Marie Vihonsky" <[email protected]>
> To: <[email protected]>
> Sent: Monday, February 10, 2003 3:58 AM
> Subject: Re: TZF - Many Thanks but more help needed
>
>
>
>>Hi Jerry,
>>
>>A simple question here - Why are you 'comparing' the ID's.
>>
>>If the 2nd database (300 records) got trashed and you know that the ID's
>>should 'match' bewteen the 2 databases, why not just 'regenerate' the
>>ID's in the 2nd database using the ID from the first database?
>>
>>My thought would be to:
>>1 - have the first database indexed on 'name'
>>2 - have the second database NOT indexed
>>3 - flip thru the second database, build the 'key' that should match the
>>name in the first database, do a FIND, if found, then update ID2. If NOT
>>FOUND, then show your messages and decide what to do.
>>
>>I don't have time tonight to locate some code which will do the above,
>>so if you still need it - let me know and I'll look tomorrow.
>>
>>Marie
>>
>>Jerry Mallett wrote:
>>
>>>Thank you for your response.
>>>
>>>Code as requested.
>>>
>>>procedure TForm1.Compare1Click(Sender: TObject);
>>>var fn,ln : string; // FirstName -
>>>LastName Varaibles
>>> id1, id2, x,y : Integer; // id1 = db1 member
>>>and id2 = db2 member (x & y for RecNo and RecCount)
>>> MatchFound : Boolean; // wanted to use this to
>>>exit loop when a match is found
>>>begin
>>> TzDbf.Active := True;
>>> TzDbf.GoTop;
>>> X := 1; // Initialised this
>>>for the ShowMessage window to see what was happening
>>> id2 := 0; // Initialised this
>>>for the ShowMessage window to see what was happening
>>> While NOT TzDBF.dEOF Do
>>> Begin
>>> MatchFound := False;
>>> fn := Trim(TzDBF.GetCField('firstname')); // get
>>>firstname
>>> ln := Trim(TzDBF.GetCField('lastname')); // get
>>>lastname
>>> id1 := TzDBF.GetLongField('memberid'); // get current
>>>id number
>>>
>>> // Show it on screen to see if all is ok
>>>
>>> ShowMessage('Competitor - '+fn+' '+ln+
>>> ' is currently '+IntToStr(id1)+
>>> ' but should be '+IntToStr(id2));
>>>
>>> CompetitorsFrm.Competitors.Active := True;
>>> CompetitorsFrm.Competitors.GoTop;
>>> y := CompetitorsFrm.Competitors.RecCount; // get the total
>>>number of records in main database (db1)
>>> For x := 1 to y Do
>>> Begin
>>> If (fn =
>>>Trim(CompetitorsFrm.Competitors.GetCField('firstname'))) AND
>>> (ln =
>>>Trim(CompetitorsFrm.Competitors.GetCField('lastname'))) Then
>>>
>>> Begin // we found a match so enter and
>>>update/correct the db2 file
>>> MatchFound := True;
>>> id2 :=
>>>CompetitorsFrm.Competitors.GetLongField('memberid'); // get the
>>>membership number from current record
>>>
>>> // lets display it on screen to check we have got this far
>>>
>>> ShowMessage( ' Record No.'+IntToStr(x)+
>>> ' = Competitor - '+fn+' '+ln+
>>> ' is currently '+IntToStr(id1)+
>>> ' but should be '+IntToStr(id2));
>>>
>>> TzDbf.SetLongField('memberid',id2); // write it to db2
>>> TzDbf.Post; // post it
>>>to db2
>>> End
>>> Else
>>> // ok got lost here.....tried to do x := y which
>>>is total recordcount so that i could exit loop but it won't compile
>>>
>>> If MatchFound Then // then tried the boolean op. but
>>>....help.
>>> CompetitorsFrm.Competitors.Go(x);
>>>
>>> End; // For x loop
>>> TzDBF.Skip(1); // skip to next record
>>> End;
>>>End;
>>>
>>>
>>>
>>>R & WL Hamilton wrote:
>>>
>>>
>>>>Can you give a code sample where it crashed? Is is a crash with an error
>>>>or an infinite loop of searching?
>>>>
>>>>How are you comparing db2 to the correct db1 number if your db2 member
>>>>number is missing or wrong?
>>>>Roger
>>>>----- Original Message -----
>>>>From: "Jerry Mallett" <[email protected]>
>>>>To: <[email protected]>
>>>>Sent: February 9, 2003 7:30 PM
>>>>Subject: TZF - Many Thanks but more help needed
>>>>
>>>>
>>>>
>>>>
>>>>>Hi Guys.
>>>>>
>>>>>Many thanks to all those that responded to my last problem.
>>>>>
>>>>>Got another one now which I have just spent 6 hours on without success.
>>>>>
>>>>>I'm self taught and still learning so go easy on me here.
>>>>>
>>>>>Two databases, First One containing all the proper and correct info on
>>>>>everyone in the club. About 1000 names addresses etc, plus a
>>>>
> membership
>
>>>>>number.
>>>>>
>>>>>Second one containing some 300 of the same names and membership numbers
>>>>>but with different data.
>>>>>
>>>>>My problem is the membership nos have gone belly up in the second
>>>>>database and I tried to write a routine to compare db2 with db1, check
>>>>>the membership number from db2 with the original in db1, if they didn't
>>>>>match update db2 with the proper membership number from db1.
>>>>>
>>>>>Used a WHILE loop to get info from each record in turn from db2 and
>>>>>nested a for next loop within the while loop which went through each
>>>>>record in turn of db1 to do a comparison. It only partly worked then
>>>>>crashed.
>>>>>
>>>>>Glad I don't do this for a living. I'd be an extremely poor man today.
>>>>>lol
>>>>>
>>>>>Needless to say I haven't succeeded and was wondering if anyone can
>>>>>help...please.....
>>>>>
>>>>>
>>>>>Jerry
>>>>
>>
>
>
>
==^================================================================
This email was sent to: [email protected]
EASY UNSUBSCRIBE click here: http://topica.com/u/?clvXPN.a5kvff.Z2NsZHQt
Or send an email to: [email protected]
TOPICA - Start your own email discussion group. FREE!
http://www.topica.com/partner/tag02/create/index2.html
==^================================================================