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;


end;
_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to