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!
  • Students Click Here

*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.

Students Click Here


how to generate barcodes using visual fox pro with the following code

how to generate barcodes using visual fox pro with the following code

how to generate barcodes using visual fox pro with the following code

Hi im using a code found at www.foxite.com which generates barcodes using a font called "upca" I just have 1 problem with the last digit. For example im passing the following digits 555555125215 which is a upc number of 12 digits that i have stored on a dbf in VFP9 (please see the link to the image below), If you see on the attached image link, all the numbers are on the barcode except the last number on the right, in my table, which is the upc number above, the last number is 5, but when generating the barcode the last digit is 6. I want to be able to generate the barcode using the string exactly as i have it store on the table. Here is the code im using. All my upc numbers are 12 digits.

* UPC.prg
* Author  : Rahul Moudgill
* Date : 10-10-10
IF EMPTY(_Code) OR TYPE("_Code")#'C'
    RETURN ""


RETURN Str2UPCa(_Code)

LOCAL m.RightVal,m.RightPart,m.MidVal,m.LeftPart,m.LeftVal
RETURN m.LeftVal+m.LeftPart+m.midVal+m.RightPart+m.RightVal

LOCAL m.AddVal, m.Val13,i
m.AddVal = 0
m.Val13 = 1

FOR m.i = LEN(_value) TO 1 STEP -1
  m.Val13 = IIF(m.Val13 = 3,1,3)
  m.AddVal = m.AddVal + (VAL(SUBSTR(_value,m.i,1)) * m.Val13)
RETURN _value + RIGHT(STR(1000-m.AddVal),1)

Base on this code can you please help me determine why the last number is changing when generating the barcode? on the links below on vfpsample.jpg, you'll see how im testing this on the vfp9 command window
Thank You

Links to images and upc font


upca font

RE: how to generate barcodes using visual fox pro with the following code

No idea about your code (I don't have time to learn yet another language), just a comment regarding the UPC value.

A UPC-A value consists of 11 digits, plus a calculated check-digit, making 12 digits in all.

You appear to be passing in all 12 digits (including the correct check-digit of 5 for the 11-digit value 55555512521), but your code is perhaps attempting to calculate another check-digit?

RE: how to generate barcodes using visual fox pro with the following code

I previously answered you in the VFP Forum, but also advised that this question should have been posted here instead of VFP because the question really isn't about VFP use, but about how to calculate a valid UPC-A barcode and then, after that, print it out - the language used is VERY secondary.

You can find the UPC-A specification pretty clearly explained at:

On that site you will find the method of calculating the UPC-A Check Character.

If you doubt the code you have above, then calculate it yourself by hand using the method detailed on the reference site.
NOTE - personally I would have done my own VFP calculation using a different approach.

If, after that, you believe that the code above is not working correctly, write your own code.

In general, regardless of the language used...


cUPCRawBarcode = < NumSys1 + MfgCode5 + ProdCode5 >
cUPCChkDigit = CalcChkDigit(cUPCBarcodeString)  && Calculate
cUPCBarcodeString = cUPCRawBarcode + cUPCChkDigit
* --- Now Print COMPLETE Barcode ---
< print it out >

Good Luck,

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! Already a Member? Login

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