Find differences in two memofields

  • Thread starter Thread starter Kees Witmans
  • Start date Start date
K

Kees Witmans

Guest
Hallo Fellow Forummembers,

I want to register differences in two memofields. For instance I have a table texts with three fields: text1, text2 and TextDifference. Field text1 contains: "This is a text." and field text2 contains: "This is a text too." Now the function I want to make should deliver de value for TextDifference i.e. "too" in this case.

Now this is just a very silly example, but is there a VBA-function you can use to determine the difference between two memo-fields? I searched this forum for solutions and I found some interesting subjects but none of them solved the problem described above. Things like StrComp and Instr do not deliver a string value but a variant indicating that there is a difference but not what the difference is.

When this is solved the next step will be to compare changes in a field. This, in order to register changes made to a field. In the case a new value and an old value of a memofield need to be compared.

Thanks in advance for your efforts.

Kees
 
kees,

If I was faced with this:

1) Write Memo1 out to File 1
2) Write Memo2 out to File 2
3) Shell & Wait for the DOS fc utility --> output to File 3
4) Read File 3 into Memo3 and display differences

Wayne
 
WayneRyan said:
kees,

If I was faced with this:

1) Write Memo1 out to File 1
2) Write Memo2 out to File 2
3) Shell & Wait for the DOS fc utility --> output to File 3
4) Read File 3 into Memo3 and display differences

Wayne

Is step 3 a standard DOS function? If so how do you use it?

I would have created 3 varibles and looped through the charactors one at a time writing the different ones to the 3rd variable.

Something like this (THIS IS JUST ROUGH NOT TESTED~!!)

Call it with

Code:
MsgBox FindDifference(memo1,memo2)

Private Function FindDifference(string1 as string, string2 as string) as string

dim i as integer

for i = 1 to len(String1)

if not mid(string1,i,1) = mid(string2,i,1) then
FindDifference = FindDifference & mid(string1,i,1)
end if
next i

End Function
 
Jerry,

Yes, but it finds the differences between two files.

Just go to the Command Prompt and type "Help FC". DOS actually has
a few different utilities like that. The best is on a VAX computer system.

Your code will just find the first character that is different. Some of the
OS Difference utilities are quite complex. They can point out what line
has been inserted in the middle of a text file, re-synch, and process the
rest of the file.

With the original post here, I figured that the output from the utility would
be more meaningful. If you just insert a character (or word) in memo #2,
your code (and any that I would write) won't get the two fields back in
"synch".

Wayne
 
Yeah I am aware of the flaws in the code I wrote. I deffinately like your way better. Just wasnt sure of how to use it. Like if there was an extra space somewhere mine would throw the rest of the charactor set off and return it as being different.

Thanks man!!!
 
Kees & Jerry,

Didn't try to make it look good ... but it's functional.

Wayne
 

Attachments

Users who are viewing this thread

Back
Top Bottom