Jump to content

Calclate a Check Digit


matthall

Recommended Posts

Hi,

 

I am required to calculate a check digit at the end of a 27 character string. I have the string (separately constructed and held) in a Variable. I include the basic logic for calculating this below.

Of the string the majority of characters are numeric and so do not need converting to numeric alternatives as per step one. That said, the first seven characters will be formed of the postcode and so may need these conversions on any given character (where the postcode is shorter than 7 characters 0 is used to fill).

 

Can anyone advise on the best way to accomplish this task?

 

Can I do multiple looping calculations within a single varibale?

Will I need a scriptlet instead? Can someone talk me through creating one because i have no idea!?

 

 

-----------------------------------------

28 & 14 Digit Check Digit Calculation

 

Function to create a Check digit for barcode strings using ISO 7064 Mod 37, 36

 

This calculation is also to be used to generate the Parcel Tracking No: check digit.

 

 

Maintain two variables through the function:

V             initialised to zero Reset for use on each character.

Cd           initialised to 36     Running value maintained through the function.

 

Loop through all the characters of the string

 

 

 

 

For each character

 

Calculate V where;

    0=0, 1=1, 2=2, 3=3,….

    A=10, B=11, C=12, D=13,E=14,…..

 

 

----------------------------------

Add the resultant V to running value Cd

If Cd is greater than 36 then subtract 36 from Cd.                        (Cd = Cd – 36)

----------------------------------

Multiply Cd by 2   (this value is now an even number between 2 and 72)

----------------------------------

If Cd is greater than 36 then subtract 37 from Cd.                        (Cd = Cd – 37)

----------------------------------

After all characters have been processed:

 

Subtract the resultant Cd from 37                                                                    (Cd = 37 – Cd)

If Cd equals 36 then reset Cd to Zero

 

 

 

 

 

 

Once cycled through all characters the resultant Cd is converted back to a check digit, where;

    0=0, 1=1, 2=2, 3=3,….

    A=10, B=11, C=12, D=13,E=14,…..

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

  • 5 weeks later...

Returning to this a month on...

 

I tried to pass each digit through individual variables but cam up against a 'maximum file size' problem.

Now investigating user defined functions to reduce the large but repeptitive functions into smaller call functions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...