Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #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
Poder: 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
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Cálculo de los dígitos IBAN Troffed Trucos 9 26-07-2020 18:08:27
validación Nelly Varios 8 12-10-2005 19:32:33
validacion halifax Tablas planas 7 06-02-2005 23:25:53
Validacion Carlex Conexión con bases de datos 1 08-09-2004 23:53:41
Como calcular codigo IBAN cinecito Varios 2 11-05-2004 18:49:44


La franja horaria es GMT +2. Ahora son las 14:36:21.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi