Who is Participating?

I think I understand now - You want to totally ignore the final two digits when the value is being processed and simply replace them at the very end of the calculation (ie you could have the last two dogots as any value and they won't affect the checksum as it's based on the rest of the value).

VAR
iValue : INT64;
iResult : INT64;
sValue : STRING;
begin
sValue := '220401000207682';
//Get the stribg into an integer
iValue := BigStrToInt(sValue);
//We're only interested in the final two digits for calculating the checksum
//BUT we need remember the rest of the value (minus the last two digits) so
//strip off the last two digitd by dividing by 100
iResult := iValue DIV 100;
//Divide the COMPLETE value by 97
iValue := ((iValue DIV 100) * 100) MOD 97;
//Calculate the checksum
iValue := (97 + 1) - iValue;

//Add the two checksum digits to the end of the value
//iResult is the original number but with the last two digits stripped. If we
//add on two extra zeroes (by multiplying by 100), we can then add the
//checksum value straight onto the end to give us a final value
iResult := iResult * 100 + iValue;

ShowMessage('Result: ' + IntToStr(iResult));
end;

Although it looks to be just about the same code, it's now replacing the final two dogits with zeroes BEFORE doing the checksum calculation. After it's done the calculation it then just replaces the final two dogots with the checksum value. Hope that's what you needed

Well it depends on which values you're putting into it that are causing the error (the access voliation itself means nothing). I did spot one thing though (but I don't think it's the problem), try adding a Exit to the first IF statement:

if Copy(DBEdit7.Text,1,1) = '4' then //Od Mohhamed
begin
ShowMessage('Value must not start with a 4');
Table2.Cancel;
Exit;
end;

Beyond that then it's a case of looking at the data. Can you post a value (or values) that are causing problems?

The Neil =:)

0

blashAuthor Commented: 2001-06-26

Dear The Neil,

After cheking out my question, I saw that I must redefine it. I'll do that later during the day. I'll try that "Exit;" anyway. Thanks for helping me.

Greetings, Blash

0

blashAuthor Commented: 2001-06-26

Hi The Neil,

The 15 digit number is:

Num:=220840001229500

The last 2 digits are not zeroes by default.
To get the "control number" I have to perform the following calculation:

I divide Num with 97, but I need the reminder, that's:

220840001229500 mod 97, so the reminder is 9.

So now I need this reminder "9" for the "control number":

(97+1)-"reminder"=(97+1)-9=89

So now my Num2: is:

2208400012295/89

If the "reminder" would be "0" then by default the "control number" would be "89".

VAR
iValue : INT64;
iResult : INT64;
sValue : STRING;
begin
sValue := '220840001229500';
//Get the stribg into an integer
iValue := BigStrToInt(sValue);
//We're only interested in the final two digits for calculating the checksum
//BUT we need remember the rest of the value (minus the last two digits) so
//strip off the last two digitd by dividing by 100
iResult := iValue DIV 100;
//Divide the COMPLETE value by 97
iValue := iValue MOD 97;
//Calculate the checksum
iValue := (97 + 1) - iValue;

//Add the two checksum digits to the end of the value
//iResult is the original number but with the last two digits stripped. If we
//add on two extra zeroes (by multiplying by 100), we can then add the
//checksum value straight onto the end to give us a final value
iResult := iResult * 100 + iValue;

ShowMessage('Result: ' + IntToStr(iResult));
end;

The Neil =:)

0

blashAuthor Commented: 2001-06-29

Dear The Neil :)))

The code works prefectly, only one thing:

How can I say in code at the place where:

sValue:='220840001229500';

take care only for the first 13 digits,leave the 14th and 15th alone (thats taken care later with:

I'm not sure what you mean. As it stands, the code strips off the last two digits (14th and 15th) works out the checksum and then adds the two new values onto the end when it's finished (so you end up with the same number of digits). It's effectively ignoring the 14th and 15th digits and only basing it's calculation on the first 13

The Neil =:(

0

blashAuthor Commented: 2001-07-02

Dear The Neil :)))

So sorry that I'm nagging you with my stupid question. You have more then deserved my pityful 50 points. Have you had a nice weekend? I hope this would be the last that you hear from me - concerning this question.

Your code works perfectly for me if I, for example, have this number:
220401000207682, but only if I enter it as:
220401000207600.

In fact I need, after running your procedure that:
sValue: would be the same as iResult: