0

Having an issue when attempting to run a Mod formula against a field. I keep receiving the error "String is Not Numeric" and so far I have not been able to get ToNumber to correctly format the field. The field is being generated by adding a static value and three fields that have been padded. Any help would be appreciated.


Combines fields and pads

StringVar strMICR;
StringVar strMICRLINE;


strMICRLINE := Chr(13) & "0603250694";
strMICRLINE := strMICRLINE & Right("000000" & Trim(Split({CUST.C_ID_ALPHA},"-")[1]),6);
strMICRLINE := strMICRLINE & Right("00000000" & ToText({STMT.STMT_NUMBER},0,""),8);
strMICRLINE := strMICRLINE & Right("0000000000" & Replace(ToText({@Total},2,""),".",""),10);


//Uncomment below to test Mod10 Check-digit
//strMICR := mod10("0603250694084469108961440000127874");

//IF NumericText (strMICRLINE) 
//THEN ToNumber (strMICRLINE);

Mod10 (strMICRLINE);

MOD10 Function

Function (StringVar input_number)

input_number := replace(input_number, " ", "");

numbervar i := length(input_number);
numbervar sum_val := 0;

stringvar position := "odd";

do (
    if position = "odd" then (
        sum_val := sum_val + 3*tonumber(input_number[i]);
        position := "even" )
    else (
        sum_val := sum_val + tonumber(input_number[i]);
        position := "odd" )
    ;

    i := i-1
)  while i > 0;

numbervar remainder_val := Remainder(sum_val, 10);

numbervar check_digit := if remainder_val = 0 then 0 else (10-remainder_val) ;

input_number + ToText(check_digit, 0)
Ryan
  • 7,212
  • 1
  • 17
  • 30

1 Answers1

0

You're attempting to call toNumber() on a string that is not numeric and therefore can't be converted. You need to strip all non-numeric characters out of your string first.

//Formula sample to strip non-numeric characters
local stringvar input := "78906-adf0asdf-234";
local stringvar output;
local numbervar i;

for i:=1 to length(input) do
  if numerictext(input[i]) then output:=output&input[i];

output

Then I would highly suggest you use the built in mod function instead of rolling your own.

toNumber({@NumericTextOnly}) mod 10
Ryan
  • 7,212
  • 1
  • 17
  • 30
  • The thing i dont understand is that the string being input is numeric. I can see when it errors out that the value it has in the MOD10 function for input_number is "0603250694001002000000120000004875". So i dont understand why the toNumber is not functioning. – Vince Flynn Mar 31 '15 at 14:04
  • How do you know that's the value that causes the error? I just tried it; your function works for that value. The problem is that the report is simply passing a non-numeric string to that function at some point and the function does not handle it gracefully. – Ryan Mar 31 '15 at 14:17
  • Keep in mind that non-printable characters and white space characters (including `chr(13)`) will cause the error as well. – Ryan Mar 31 '15 at 14:23