Ver Mensaje Individual
  #5  
Antiguo 02-12-2013
Avatar de defcon1_es
defcon1_es defcon1_es is offline
Miembro
 
Registrado: mar 2004
Ubicación: Cuenca - España
Posts: 533
Reputación: 21
defcon1_es Va por buen camino
Muchas gracias por el aporte.

Para los que usamos Delphi en vez de C++ Builder, les dejo la "traducción" de la función a Pascal.

Código Delphi [-]
function TForm1.Generar_IBAN(Pais, Cuenta: string): string;

  function EsAlfanumerico(Caracter: Char): boolean;
  begin
    Result := (AnsiChar(Caracter) in ['A'..'Z', 'a'..'z']);
  end;

  function EsNumerico(Caracter: Char): boolean;
  begin
    Result := (AnsiChar(Caracter) in ['0'..'9']);
  end;

var cAux, AuxCuenta:string;
    i:Integer;
    auxTemp: Extended;
begin
  if (Trim(Cuenta) = '') or (Length(Cuenta) > 34)
  then Result := ''
  else begin
// Fase 1: Nos aseguramos que solo contiene Letras y Numeros
    Cuenta := UpperCase(Cuenta);
    AuxCuenta := Cuenta;
    cAux := '';
    for i := 1 to Length(Cuenta) do
     if (EsAlfanumerico(Cuenta[i]) or EsNumerico(Cuenta[i]))
     then cAux := cAux + AnsiString(Cuenta[i]);

    Cuenta := cAux;
// Fase 2: Se comprueba si ya es un codigo IBAN, y si no lo es, se añade el PAIS
    if (EsAlfanumerico(Cuenta[1]) and EsAlfanumerico(Cuenta[2]))    // Es IBAN
    then begin
     if (EsAlfanumerico(Cuenta[3]) or EsAlfanumerico(Cuenta[4]))
     then Result := '';
     Cuenta := Copy(Cuenta, 5, Length(Cuenta));//Cuenta.SubString(5, Length(Cuenta)) + Cuenta.SubString(1, 2) + '00';
     Pais   := Copy(Cuenta, 1, 2);//Cuenta.SubString(1, 2);
    end
    else begin
  //y si no lo es, se añade el PAIS
     if (Trim(Pais) = '') then Pais := 'ES';
     Cuenta := Cuenta + Pais + '00';
    end;

// Fase 3: Se convierten las letras del pais en sus numeros equivalentes:
  //A=10, B=11, C=12 ... Z=35
    cAux := '';
    for i := 1 to Length(Cuenta) do
    begin
     if (EsAlfanumerico(Cuenta[i]))
     then cAux := cAux + FormatFloat('00', Ord(Cuenta[i])-55)//Cuenta[i - 1] - 55)
     else cAux := cAux + Copy(Cuenta, i, 1);
    end;
    Cuenta := cAux;
// Fase 4: Dividimos por 97
    auxTemp := StrToInt(Copy(Cuenta, 1, 9)) mod 97;
    cAux   := FormatFloat('0', auxTemp);//FormatFloat("0", StrToInt(Cuenta.SubString(1, 9)) % 97);
    Cuenta := Copy(Cuenta, 10, Length(Cuenta));//Cuenta.SubString(10, Cuenta.Length());
      while (Trim(Cuenta) <> '') do
      begin
        if (StrToInt(cAux) < 10)
        then begin
          cAux   := cAux + Copy(Cuenta, 1, 8);//Cuenta.SubString(1, 8);
          Cuenta := Copy(Cuenta, 9, Length(Cuenta));//Cuenta.SubString(9, Cuenta.Length());
        end
        else begin
          cAux   := cAux + Copy(Cuenta, 1, 7);//Cuenta.SubString(1, 7);
          Cuenta := Copy(Cuenta, 8, Length(Cuenta));//Cuenta.SubString(8, Cuenta.Length());
        end;
        auxTemp := StrToInt(cAux) mod 97;
        cAux := FormatFloat('0', auxTemp);
      end;
// Fase 5: Devolvemos el IBAN completo con sus digitos de control.
// Se puede cambiar para devolver solo el digito de control, o lo que se quiera.
      Result := Pais + FormatFloat('00', 98 - StrToInt(cAux)) + AuxCuenta;
    end;
  end;
end;
__________________
Progress Openedge
https://abevoelker.com/progress_open...dered_harmful/


Delphi forever...
Responder Con Cita