Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Keeping the zero on the left after val ( )
Message
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01258472
Message ID:
01258503
Vues:
15
This message has been marked as the solution to the initial question of the thread.
It's ugly code. There's no need to convert number to string to get its digits, neither there's a need to emulate an array with memory variables in VFP.
The code below (not tested) shows a proper way
lnVal2Test = ln
DIMENSION laR[9]
FOR i=9 TO 1 STEP -1
	laR[i] = lnVal2Test % 10
	lnVal2Test = INT(lnVal2Test /10)
ENDFOR
lnDv = laR[9]
lnSum = (laR[1] * 8) + (laR[2] * 6) + (laR[3] * 4) + (laR[4] * 2) + ;
			(laR[5] * 3) + (laR[6] * 5) + (laR[7] * 9) + (laR[8] * 7)
>Please take a look at the code below:
>
>** the last one is the verify digit
>
>
>LN = VAL (DIRETO.REG)
> endif
>
>
>FOR lnCounter = 1 TO LEN(ALLTRIM(STR(ln)))
>lcVarName = 'lcVarName' + ALLTRIM(STR(lnCounter))
>&lcVarName = INT(VAL(substr(trans(ln),lnCounter,1)))
>ENDFOR
>
>R1 = lcVarName1
>R2 = lcVarName2
>R3 = lcVarName3
>R4 = lcVarName4
>R5 = lcVarName5
>R6 = lcVarName6
>R7 = lcVarName7
>R8 = lcVarName8
>DV = lcVarName9
>
>
>Sum = (R1 * 8) + (R2 * 6) + (R3 * 4) + (R4 * 2) + (R5 * 3) + (R6 * 5) + (R7 * 9) + (R8 * 7)
>
>REST1 = MOD(Sum, 11)
>
>DO CASE
>CASE REST1 = 0
>DV1 = 5
>CASE REST1 = 1
>DV1 = 0
>OTHER
>DV1 = 11 - REST1
>ENDCASE
>
>IF DV1 # DV
>
>= MESSAGEBOX ("invalid code")
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform