| Validando Titulo de Eleitor |
|
|
|
| Dicas - String | ||||
|
function ValidaTituloEleitor(NumTitulo: string): Boolean; var i, Soma : integer; sTitulo: string; Resto, Dig1, Dig2 : double; begin sTitulo := ''; for i := 1 to Length(NumTitulo) do if (Copy(NumTitulo,i,1) >= '0') and (Copy(NumTitulo,i,1) <= '9') then sTitulo := sTitulo + Copy(NumTitulo,i,1); sTitulo := FormatFloat('0000000000000', StrToFloat(sTitulo)); Soma := StrToInt(sTitulo[1]) * 2 + StrToInt(sTitulo[2]) * 9 + StrToInt(sTitulo[3]) * 8 + StrToInt(sTitulo[4]) * 7 + StrToInt(sTitulo[5]) * 6 + StrToInt(sTitulo[6]) * 5 + StrToInt(sTitulo[7]) * 4 + StrToInt(sTitulo[8]) * 3 + StrToInt(sTitulo[9]) * 2 ; Resto := Soma mod 11; if (Resto = 0) or (Resto = 1) then begin if (Copy(sTitulo,10,2) = '01') or (Copy(sTitulo,10,2) = '02') then begin if Resto = 0 then Dig1 := 1 else Dig1 := 0; end else Dig1 := 0 end else Dig1 := 11 - Resto; Soma := StrToInt(FloatToStr((StrToInt(sTitulo[10]) * 4) + (StrToInt(sTitulo[11]) * 3) + (Dig1 * 2))); Resto := Soma mod 11; if (Resto = 0) or (Resto = 1) then begin if (Copy(sTitulo,10,2) = '01') or (Copy(sTitulo,10,2) = '02') then begin if Resto = 0 then Dig2 := 1 else Dig2 := 0; end else Dig2 := 0; end else Dig2 := 11 - Resto; if (StrToInt(sTitulo[12]) > Dig1) or (StrToInt(sTitulo[13]) > Dig2) then Result := False else Result := True; end; Enviada por: Guilherme Agradecimento também ao Rodrigo Ferreira Duarte que enviou uma dica bem parecida! valeu!!
|
||||



