Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mod10 Formula 2

Status
Not open for further replies.

jbusby825

Technical User
Feb 3, 2017
3
US
In a post I found ( I used the formula that was presented here and it seems to work except that I keep getting "A string is required here" error.

I'm getting the error on line 8 (counting blank lines) of the code where it says replace({ACCOUNT_CARD_DATA.CARD_NUMBER}," ","")

If I add totext and make it say replace(totext({ACCOUNT_CARD_DATA.CARD_NUMBER})," ","") it will save with no errors but when I try to put it in the report it gives me a "The string is non-numeric" error. When I click ok it shows me the error in the code is on line 18 (counting blank lines) where it says v_calc := tonumber(v_temp) * 2

I feel like I'm in a loop that can't be resolved...what am I doing wrong?

Thank you!

Code:
whileprintingrecords;
stringvar v_cc := "";
stringvar v_temp := "";
numbervar v_calc := 0;
numbervar v_result := 0;
numbervar v_counter := 0;

v_cc := replace({ACCOUNT_CARD_DATA.CARD_NUMBER}," ",""); //THIS IS THE 1ST PLACE I'M GETTING THE ERROR

// Double every other digit starting with the last digit.

numbervar v_counter := len(v_cc);

while v_counter > 0

do
(v_temp := mid(v_cc,v_counter,1);
v_calc := tonumber(v_temp) * 2; //THIS IS THE 2ND PLACE I'M GETTING THE ERROR

if v_calc >= 10 then v_calc := tonumber(left(totext(v_calc,"#",0),1))+ tonumber(right(totext(v_calc,"#",0),1))
else
v_calc;

v_result := v_result + v_calc;
v_counter := v_counter - 2);

// Add in the non-doubled digits
v_counter := len(v_cc) - 1;

while v_counter > 0

do
(v_temp := mid(v_cc,v_counter,1);
v_calc := tonumber(v_temp);
if v_calc >= 10 then v_calc := tonumber(left(totext(v_calc,"#",0),1)) + tonumber(right(totext(v_calc,"#",0),1))
else
v_calc;

v_result := v_result + v_calc;
v_counter := v_counter - 2);

// Calculate check digit
v_cc + right(totext(v_result * 9,"#",0),1)
 
Your problem here is that the starting point of ({ACCOUNT_CARD_DATA.CARD_NUMBER} is a number, where the formula expects a string.

Amend the formula as follows to convert ({ACCOUNT_CARD_DATA.CARD_NUMBER} to a string, bi changing line 8 as follows:

Code:
v_cc := replace(ToText({ACCOUNT_CARD_DATA.CARD_NUMBER}, '#')," ","");

Hope this helps.

Cheers


Pete
 
Thank you pmax9999 for your suggestion. You are correct, my field is a number. When I change that, it will save the formula, but then I receive a "The string is non-numeric" error and it points me to line 18 (counting blank lines) where the code says v_calc := tonumber(v_temp) * 2;. Any thoughts on that part?

Thank you!

Jesse
 
Did you add the formatting argument to the totext function? Should be:

replace(totext({@PO#},"#")," ","")

-LB
 
Replace {@PO#) with your field. I was just testing this with an alternative field.

-LB
 
This worked! Thank you so much! pmax9999, i'm not sure what i did the first time to screw up what you suggested, but that was correct. I appreciate it!

Thanks!
Jesse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top