0
votes

I have put a formula to display the value of a field after masking it in crystal reports. but it shows me an error 'The string is non-numeric' in cardno variable. Following is code of my formula:

StringVar cardno;
NumberVar current_len;
NumberVar card_len;
NumberVar start;
NumberVar last;
StringVar ca;

card_len := ToNumber (Mid ({@lens},1,2));
start    := ToNumber (Mid ({@lens},3,2));
last     := ToNumber (Mid ({@lens},5,2));

current_len := Length (Trim (ToText({CA.CA}, 0 ,'')));

ca := ReplicateString("0",card_len-current_len) + Totext({CA.CA},0,'');

If card_len > current_len Then
    If start = 0 Then
        If last <= 1 Then
            cardno := Mid(ca, last, card_len)            
        Else
            cardno := ReplicateString("X",last-start-1) + Mid(ca, last, card_len)           
Else
    cardno := Mid (ca,1,start) + ReplicateString("X",last-start-1) + Mid(ca, last, card_len);

Please provide a solution to avoid this error. Thanks in advance.

1
Will you post an example of what the number resembles and the desired mask? - craig
I need cardno like " cardno= XXXXXX1234 ". - maddy2012
Is the string's length constant? Or what are the valid lengths? - craig
Also, what is the @len formula based on? Is it possible that the formula can be null or not start with at least 6 numeric characters? I've only seen the error you're getting from a ToNumber() function call. - Ryan
So, you want to mask all but the last 4 digits of a string representation of number (presumably a credit-card number)? My answer will do just that. - craig

1 Answers

0
votes

Why don't you do something like this:

Select Len({table.field})

//AmEx
Case 15:  Picture({table.field}, "XXXX XXXXXX XXXXX")

//Visa
Case 16:  Picture({table.field}, "XXXX XXXX XXXX XXXX")

Default:  {table.field}

** edit **

Replace(Space(Len({table.field})-4), " ", "X") + Right({table.field},4)