INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Mod10 Formula

Mod10 Formula

(OP)
In a post I found (http://www.tek-tips.com/viewthread.cfm?qid=1674167) 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) 

RE: Mod10 Formula

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

RE: Mod10 Formula

(OP)
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

RE: Mod10 Formula

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

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

-LB

RE: Mod10 Formula

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

-LB

RE: Mod10 Formula

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close