Einzelnen Beitrag anzeigen

Amateurprofi

Registriert seit: 17. Nov 2005
Ort: Hamburg
1.041 Beiträge
 
Delphi XE2 Professional
 
#5

AW: Prüfziffer für IBAN berechnen

  Alt 12. Sep 2013, 13:43
Was in #1 nicht erwähnt wurde, ist, dass die Prüfziffern nicht 00 oder 01 sein darf.

Hier eine Funktion, die aus BLZ (8-stellig) und Kontonummer (10-stellig) eine "Deutsche" IBAN erstellt.


Delphi-Quellcode:
FUNCTION CreateGermanIBAN(Const BankCode,Account:String):String;
const csmax=(High(NativeUInt)-9) div 10;
var cs:NativeUInt; i,cc:integer; s:string;
begin
   if (Length(BankCode)<>8) or (Length(Account)<>10) then Exit('');
   s:=BankCode+Account+'131400'; // 131400 = 'DE00'
   cs:=0;
   for i:=1 to Length(s) do begin
      if cs>csmax then cs:=cs mod 97;
      cs:=cs*10+Ord(s[i])-Ord('0');
   end;
   if cs>96 then cs:=cs mod 97;
   cc:=98-cs;
   if cc<2 then inc(cc,97); // 00-->97, 01--> 98
   result:='DE00';
   result[3]:=Chr(cc div 10+Ord('0'));
   result[4]:=Chr(cc mod 10+Ord('0'));
   result:=result+BankCode+Account;
end;
Gruß, Klaus
Die Titanic wurde von Profis gebaut,
die Arche Noah von einem Amateur.
... Und dieser Beitrag vom Amateurprofi....
  Mit Zitat antworten Zitat