Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Modulus 97 on a very large number
Message
De
05/04/2007 17:23:32
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01200962
Message ID:
01212737
Vues:
24
Hans,
I presume you are making an IBAN checker, here is my solution I made couple of years ago, most probably I would do it differently today, nevermind, it still works:
lnLength=len(alltrim(lcNumber2Check))
* first change the alpha's  to digit
for lnPosition = 1 to lnLength
	lcCheckDigit = substr(lcNumber2Check,lnPosition,1)
	if isalpha(lcCheckDigit)
		lcCheckDigit = asc(lower(lcNumber2Check,))-87)
		lcNwNumber = lcNwNumber+alltrim(str(lcCheckDigit,8,0))
	else
		lcNwNumber = lcNwNumber+lcCheckDigit
	endif
endfor

* now find the mod(97) for the first part of 9 digits only
lnNumber1 = mod(val(substr(lcNwNumber,1,9)),97)
* save it as character
lcMod = alltrim(str(lnNumber1,20,0))

* go on for the rest always adding the mod(97) of the previous part to the next part of 9 digits
for lnPart = 10 to 24 step 7
	lcCheckModNumber = lcMod+(substr(lcNwNumber,1,9)),97)
	lnNumber2 = mod(val(lcCheckModNumber,97)
	lcMod = alltrim(str(lnNumber2,20,0)
endfor

lnResult = val(lcMod)
* if mod = 1 iban is correct
if lnResult = 1
	return .t.
endif
Regards,
Koen
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform