Por si a alguin le interesa, he aqu铆 como calcular el C贸digo de Control del DNI Espa帽ol.
Muy sencillo. Espero que os sirva
Un saludo
FUNCTION HallaDC(cBanco,cOficina,cCuenta) 聽 聽// 聽cBanco -> CODIGO DEL BANCO (4 Caracteres)
LOCAL aVals := {1,2,4,8,5,10,9,7,3,6} 聽 聽 聽聽 // 聽cOficina -> CODIGO OFICINA (4 Caracteres)
LOCAL nCont,nTot,nRest1,nRest2 聽 聽 聽 聽 聽 聽 聽 // 聽cCuenta -> CODIGO CUENTA (10 Caracteres)
LOCAL cCod := "00"+cBanco+cOficina
nTot := 0
FOR nCont =1 TO 10
聽 聽 nTot += ( VAL(SUBSTR(cCod,nCont,1)) * aVals[nCont] )
NEXT
nRest1 := 11 - (nTot % 11) 聽 聽// COMPLEMENTO A 11
nRest1 := IF(nRest1=11,0,IF(nRest1=10,1,nRest1))
cCod := cCuenta
nTot := 0
FOR nCont =1 TO 10
聽 聽 nTot += ( VAL(SUBSTR(cCod,nCont,1)) * aVals[nCont] )
NEXT
nRest2 := 11 - (nTot % 11) 聽 聽// COMPLEMENTO A 11
nRest2 := IF(nRest2=11,0,IF(nRest2=10,1,nRest2))
RETURN 聽( ALLTRIM(STR(nRest1))+ALLTRIM(STR(nRest2)) ) 聽// DEVUELVE EL DC (2 Carateres)Muy sencillo. Espero que os sirva
Un saludo
Peaaaaaso de foro...
FWH 2007 - xHarbour - BCC55
FWH 2007 - xHarbour - BCC55