Pascal/Turbo Pascal - Validar DNI, no me funcina

 
Vista:

Validar DNI, no me funcina

Publicado por Santiago Cinel (1 intervención) el 06/10/2020 23:44:36
ayuda porfa, necesito validar q DNI(string) solo le ingresen números y no letras. Se que es con el ioresult pero no me funciona, como sería???
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 112
Bronce
Ha mantenido su posición en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

Validar DNI, no me funcina

Publicado por juanba (40 intervenciones) el 08/10/2020 07:54:06
Aqui tienes una sugerencia:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Entrada de numeros de DNI a un string
 
program numeros;
uses Crt;
const NoDNI = '********';
var DNI: string;
 
function LeerDNI: string;
var s: string;
    ch: char;
    n: integer;
    IOerror: integer;
begin
  n := 1;                            // Inicializar n a un valor <> 0
  s := '';
 
  write('Introduzca los 8 numeros del DNI, porfa [S para salir]: ');
 
  repeat                               // Ir leyendo los digitos uno a uno
{$I-}
    ch := ReadKey;
{$I+}
    IOError := IoResult;
    if IOError = 0 then                // Caracter recibido correctamente
    begin
      if (ch >= '0') and (ch <= '9') then      // Digito Ok
      begin
        s := s + ch;                   // Añadirlo a los anteriores
        write(ch);                     // y ponerlo en la pantalla
      end;
    end else
      ch := #0;                        // Esto es una seguridad un tanto paranoica
  until (Length(s) = 8) or (UpCase(ch) = 'S');
 
  writeln;
  if Length(s) = 8 then                 // Ha terminado el bucle repeat con un DNI de 8 digitos
    LeerDNI := s
  else                                  // Ha terminado con la tecla 'S'
    LeerDNI := NoDNI;
end;
 
begin
  clrscr;
  repeat
    DNI := LeerDNI;
    if DNI <> NoDNI then
    begin
      writeln('El DNI es ', DNI);
      writeln;
      readkey;
    end;
  until DNI = NoDNI;
  writeln('Fin de Programa. Vuelva cuando quiera.');
  ReadKey;
end.

Buena suerte.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar