John Meyer wrote: > I'm going through a Luhn algorhythm exercise and I can't seem to either > pick off an individual character or turn it into a integer. Here's the > code: > > var > d_Digit: Integer; > d_Sum: Integer; > //d_Length: Integer; > d_Character: AnsiChar; > d_iPos: Integer; > begin > //d_Length := strlen(PAnsiChar(Value)); > //flip the string > Value := AnsiReverseString(Value); > d_iPos := 1; > d_Sum := 0; > for d_Character in Value do > begin > d_Digit := Integer(d_Character); > if d_iPos mod 2 = 0 then > begin > d_Digit := d_Digit * 2; > if d_Digit >= 10 then > d_Digit := d_Digit - 9; > end; > d_Sum := d_Sum + d_Digit; > d_iPos := d_iPos + 1; > end; > if d_Sum mod 10 = 0 then > begin > Result := True; > end > else > Result := False;
Well, you're certainly turning it into an integer. But let me guess: You're finding that your digit is _always_ greater than or equal to 10? Have you used the debugger to see what integers you're getting? The Char value for the symbol of the number 5 is not the same as the number 5. Try using the StrToInt function. -- Rob _______________________________________________ Delphi mailing list -> [email protected] http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

