VFP开源项目之:条码工具-FoxBarcode

时间:2021-12-18 13:19:46

FoxBarcode是一个100%的Visual FoxPro类,可以根据不同的条码编码生成图像,应用于VFP表单和报表,也可以应用于其他应用程序。

作者:Francis (French MVP VFP)

下载:http://vfpx.codeplex.com/downloads/get/385679

Properties

FoxBarcode allows greater control over the generation of bar code image to be able to customize the following properties:

  • VFP开源项目之:条码工具-FoxBarcode nImageHeight: Height in pixels of the image.
  • VFP开源项目之:条码工具-FoxBarcode nImageWidth: Width in pixels of the image. NEW: Now can set the property
  • VFP开源项目之:条码工具-FoxBarcode nAlignBarcode: Allows to align the barcode on the left, center or right of the image.
  • VFP开源项目之:条码工具-FoxBarcode nResolution: Image resolution in DPI.
  • VFP开源项目之:条码工具-FoxBarcode nRotation: Rotate the image. (0 = 0°, 1 = 90°, 2 = 180°, 3 = 270°)
  • VFP开源项目之:条码工具-FoxBarcode cImageType: Type of the generated image ("JPG", "GIF" "PNG", "BMP", "TIF")
  • VFP开源项目之:条码工具-FoxBarcode cImageFile: Name the image file generated. If not specified, it generates a random file name in the folder Windows temporary files.
  • VFP开源项目之:条码工具-FoxBarcode cText: Text encoding.
  • VFP开源项目之:条码工具-FoxBarcode nAlignText: Alignment of human-readable text. (0 = Left, 1 = center, 2 = Right)
  • VFP开源项目之:条码工具-FoxBarcode lShowHumanReadableText: .T. whether to display the human-readable.
  • VFP开源项目之:条码工具-FoxBarcode lShowCheckDigit: .T. whether to display the check digit on the human-readable.
  • VFP开源项目之:条码工具-FoxBarcode lShowStartStopChars: .T. if it shows the start and end characters in human-readable.
  • VFP开源项目之:条码工具-FoxBarcode cFontName: Name of the source of human-readable.
  • VFP开源项目之:条码工具-FoxBarcode lFontBold: .T. if the source of human-readable is Bold.
  • VFP开源项目之:条码工具-FoxBarcode lFontItalic: .T. if the source of human-readable is Italic.
  • VFP开源项目之:条码工具-FoxBarcode nFontSize: Font size of the human-readable. (Recommended = 8 or 9)
  • VFP开源项目之:条码工具-FoxBarcode nFontColor: Color of the human-readable source. (Recommended = Black = RGB (0,0,0)).
  • VFP开源项目之:条码工具-FoxBarcode nBackColor: The background color of the image (Recommended = White = RGB (255,255,255)).
  • VFP开源项目之:条码工具-FoxBarcode nBarsColor: Color of the bars (Recommended = Black = RGB (0,0,0)).
  • VFP开源项目之:条码工具-FoxBarcode nBarcodeType: Type bar code symbology. See the list of supported barcodes and ID
  • VFP开源项目之:条码工具-FoxBarcode cSet128: Set of Code 128. ("A", "B", "C")
  • VFP开源项目之:条码工具-FoxBarcode cSupplementalText: Supplementary Text EAN and UPC codes.
  • VFP开源项目之:条码工具-FoxBarcode lAddCheckDigit: .T. if you calculate the check digit. In symbols, where the check digit is mandatory, not taking into account this property.
  • VFP开源项目之:条码工具-FoxBarcode nBearerBar: supporting frame type, only in the ITF-14 symbology. (0 = None, 1 = Rectangle, 2 = Top & Bottom)
  • VFP开源项目之:条码工具-FoxBarcode lUseAppId: .T. FoxBarcode interpreter to code to GS1/UCC/EAN-128 Application Identifiers (enclosed in parentheses)
  • VFP开源项目之:条码工具-FoxBarcode nFactor: Magnification factor of the bar code. (1 .. 9)
  • VFP开源项目之:条码工具-FoxBarcode nMargin: Margin around the barcode
  • VFP开源项目之:条码工具-FoxBarcode nRatio: Relationship between the narrow bars and wide bars in the symbols that allow it.

Methods

For the generation of the image, only one method should be called that generates the bar code image and returns the path and file name generated:

  • VFP开源项目之:条码工具-FoxBarcode BarcodeImage(cTextToEncode, cFileNameImage, cPropertyList): Encodes the text and returns the file path of the bar code image generated.

All parameters are optional.

  • VFP开源项目之:条码工具-FoxBarcode cTextToEncode: Text to encode.
  • VFP开源项目之:条码工具-FoxBarcode cFileNameImage: Name the image file to generate. If none is specified, it generates a random file name in the folder Windows temporary files.
  • VFP开源项目之:条码工具-FoxBarcode cPropertyList: The third parameter to set all the properties in a single line, separated by commas.

Now with the BarcodeTest() method we can validate the text to be encoded without the need to generate the image of the barcode:

  • VFP开源项目之:条码工具-FoxBarcode BarcodeTest(cTextToEncode, cFileNameImage, cPropertyList): Validate the string to encode without generating the image.

All parameters are optional, and are the same as the BarcodeImage() method.

  • VFP开源项目之:条码工具-FoxBarcode cTextToEncode: Text to encode.
  • VFP开源项目之:条码工具-FoxBarcode cFileNameImage: As an image is not generated, this parameter is an empty string.
  • VFP开源项目之:条码工具-FoxBarcode cPropertyList: The third parameter to set all the properties in a single line, separated by commas.

Languages

With the help of the Community VFP translated FoxBarcode messages the following languages:

  • ENGLISH
  • SPANISH by VFPEncoding
  • CZECH by Martin Krivka
  • DUTCH by Koen Piller
  • GERMAN by Stefan Wuebbe
  • INDONESIAN by Samir H.
  • PORTUGUESE by Cesar Ch.
  • TURKISH by Ugur Yilmaz
  • FILIPINO by Glenn Gevero
  • FRENCH by Samir H.
  • SERBIAN by Michael Kopljan
  • ITALIAN by Roberto Saccomanno

You just have to define compiler directive FBC_LANGUAGE with the desired language in the file FoxBarcode.prg.

#DEFINE FBC_LANGUAGE "ENGLISH"

You can add more languages translating messages in their native language and send email to: vfpencoding@gmail.com

Examples

The following is an example of code to generate an image type PNG barcode Code 128 C with a height of 100pixels and a magnification factor 2

*-- Create object
loFbc = CREATEOBJECT("FoxBarcode")

*-- Set the properties
WITH loFbc
  .cImageType = "PNG"
  .nBarcodeType = 110 & & Code 128
  .cSet128 = "C" & & Set 128 C
  .nImageHeight = 100
  .nFactor = 2
ENDWITH

*-- Generate image
lcImagen = loFbc.BarcodeImage("123456789012")

The new third parameter to the BarcodeImage() method, which allows you to configure the various properties, separated by commas. The same example as above, with this new way.

*-- Create object
loFbc = CREATEOBJECT("FoxBarcode")

*-- Generate image with the properties
lcImagen = loFbc.BarcodeImage("","",[cText="123456789012", cImageType="PNG", nBarcodeType=110, cSet128="C", nImageHeight=100, nFactor=2])

This are some images generated with FoxBarcode

VFP开源项目之:条码工具-FoxBarcode

VFP开源项目之:条码工具-FoxBarcode

VFP开源项目之:条码工具-FoxBarcode

VFP开源项目之:条码工具-FoxBarcode

Now FoxBarcode support code EAN/UCC/GS1 128

VFP开源项目之:条码工具-FoxBarcode

The following is an example to test if a string is valid to encode the EAN-8:

*--- Create FoxBarcode Object
LOCAL loFbc
loFbc = CREATEOBJECT("FoxBarcode")

*-- Generate a test (Ej: EAN-8 -> nBarcodeType = 150)
IF loFbc.BarcodeTest("123456", "", [nBarcodeType = 150]) 
  MESSAGEBOX(["] + loFbc.cText + ["] + " Ok", 64, "Example BarcodeTest()")
ELSE
  MESSAGEBOX(loFbc.cMsgError, 16, "Example BarcodeTest()")
ENDIF

To include a barcode on a form, you must insert an Image object. As the bar code image does not exist at design time, the Picture property takes the name of the image when calling the BarcodeImage() method, for example from the Refresh method of form, as shown in the figure below:

VFP开源项目之:条码工具-FoxBarcode

To include a barcode on a report, you must insert an Image object and set the property with a call ControlSource BarcodeImage() method and is recommended to set "contents Scale, Retain shape" if the image size differs from the frame.

VFP开源项目之:条码工具-FoxBarcode

Important: Before you run the report and create the object FoxBarcode, you must declare the variable as PRIVATE so that it has scope in the report, as follows:

PRIVATE poFbc
poFbc = CREATEOBJECT("FoxBarcode)
...
REPORT FORM MyReport

Distribution

The only files needed to be distributed to FoxBarcode function properly are:

  • VFP开源项目之:条码工具-FoxBarcode FoxBarcode.prg
  • VFP开源项目之:条码工具-FoxBarcode gpImage2.prg

These files are located in the Source folder included in the download file.

Before instantiating the class FoxBarcode, you must run the following statements:

SET PROCEDURE TO LOCFILE("FoxBarcode.prg"), LOCFILE("gpImage2.prg") ADDITIVE

Demo Form

With the download of FoxBarcode is a sample form, from which we can generate bar codes to our needs, and a builder of code, from which we can copy the generated code to the clipboard ready for pasting into your application.

At the top of the form there are three tabs from which all properties are configured class FoxBarcode.

From the tab "Barcode properties" you enter the text to encode, the kind of symbolism and if FoxBarcodecalculates the check digit. The dimensions of the image of the bar code to configure: the magnification factor, the around margin barcode, the height of the image, and the ratio of narrow and wide bar (in the symbols that allow for such variation) . The rotation of the bar code is also set from this tab, as well as some special properties of certain symbols.

VFP开源项目之:条码工具-FoxBarcode

When we go through the list of symbols, is a brief description of the selected symbols, valid characters and their more common.

VFP开源项目之:条码工具-FoxBarcode

On the tab "Human-readable properties" to configure the human-readable text, whether it will be shown, whether to display the check digit and if it shows the characters of Start and End of the symbols. The font, justification, the size and color are set in this tab.

VFP开源项目之:条码工具-FoxBarcode

The tab "Image and colors" shows us the full name of the image file, this property can be passed as parameter or FoxBarcode class generates a random file name. Here we set the image type, resolution (DPI), the background color and the color of the bars.

VFP开源项目之:条码工具-FoxBarcode

Once you've set the properties, you can click on the button "Script Builder" and FoxBarcode automatically generates the necessary code to cut and paste in your application.

VFP开源项目之:条码工具-FoxBarcode

See more examples: In English

Mire mas ejemplos: En español

Voir d'autres exemples: En français

Acknowledgements

  • To our families.
  • To Cesar Ch. for your continued ideas and collaborations with their classes gpImage2 andFoxyPreviewer.

VFP开源项目之:条码工具-FoxBarcode

Last edited Jun 4 at 4:28 AM by VFPEncoding, version 26

comments

VFPEncoding  Jun 4 at 4:43 AM 
Rogy, download the latest version of FoxBarcode 1.10 and now you can center the image and set a defined width.

See the file Example5.prg included with the download of FoxBarcode.

Luis Maria Guayan

Rogy  May 30 at 5:57 AM 
Thanks for info Luis Maria.

Is there any other way to center image on the report?

VFPEncoding  May 30 at 5:30 AM 
Rogy, 

The nImageWidth property is PROTECTED.

The nImageWidth property is set once generated the pattern according to the magnification factor and margin. Can not set in advance.

Luis Maria

Rogy  May 30 at 4:29 AM 
Hello! 
I want to center the image on the report, but I get an error (property not found) when i try to use the .nImageWidth property.

THIS.loFBC = CREATEOBJECT("FoxBarcode")
WITH THIS.loFBC
.nBarCodeType = 159
.cSet128 = "B"
.nFactor = 2
.nImageHeight = 220
.nImageWidth = 500
.lShowHumanReadableText = .T.
ENDWITH

VFPEncoding  May 3 at 1:53 AM 
Mariano, we do have the intention to implement 2D barcodes in FoxBarcode.

Unfortunately not in the near future, as Guillermo is working on another project and I am overworked.

When we begin to work on it, we will inform the VFP Community.

Luis Maria

marboccia  May 1 at 6:53 AM 
Hello everyone! I am needing to generate 2d barcode, particularly Datamatrix Ecc-200, in order to complies with GS1 requirements. Does anyone know whether this awesome project will included in the near future, meaning in a month at least. Thanks you in advance,

cmlopezrizo  Feb 18 at 4:27 AM 
Simply Great

VFPEncoding  Feb 10 at 2:02 AM 
oglethorpe: 

Use the image format PNG or BMP

Luis María Guayan

oglethorpe  Feb 9 at 8:20 PM 
The human readable text is not clear. I have tried various resolution, fonts, size, bold, etc. Nothing seems to make the UPC number clear text. I have tried 1200dpi laser printer and it is still not clear. What can I do to fix this problem?

oglethorpe  Feb 7 at 3:44 AM 
Thanks great program! Thank you! It will replace tec-it bar code library that I have been using for many years.

VFPEncoding  Jan 10 at 1:33 AM 
Edsonfat: 
What is the problem?
The name of the property is nFactor and valid values ​​are integers from 1 to 9

Ex:
goFbc.BarcodeImage("1234567890",,[cSet128 = "C", nBarcodeType = 110, nImageHeight = 34, nFactor = 1, lShowHumanReadableText = .F.])

Luis Maria Guayan

edsonfast  Jan 9 at 11:35 PM 
NF-e and CT-e Barcode: goFbc.BarcodeImage(conhecim.cte_chave,,[cSet128 = "C",nBarcodeType = 110,nImageHeight = 34, nFator = 0.6,lShowHumanReadableText = .F.])

skiwith  Oct 25, 2011 at 1:36 AM 
Looks good! Hope you get to QR soon.

Thanks.

pepere_jack  May 19, 2011 at 3:07 AM 
Good work! 

A suggestion: you could let the user specify the width of the generated image so we could get, for exemple, 200 pixel width barcode image no matther the actual length of the barcode.

Thanks.

fredkrampe  May 10, 2011 at 1:38 AM 
Luis,

The online scan readers show the barcode in upper case. It must be my scanner. Thank you very much.

Fred Krampe

VFPEncoding  May 7, 2011 at 11:20 AM 
Fred, see the code below:

SET PROCEDURE TO LOCFILE("Source\FoxBarcode.prg"), LOCFILE("Source\gpImage2.prg") ADDITIVE

PRIVATE poFbc
poFbc = CREATEOBJECT("FoxBarCode")
poFbc.cImageType = "PNG"
poFbc.nBarcodeType = 110
poFbc.cSet128 = "B"
poFBC.nImageHeight=200
poFbc.nFactor = 3

*-- I simulate a table with data in lower case
CREATE CURSOR Labels (Part C(30))
INSERT INTO Labels (Part) VALUES ("005-chp-nsg-11-02")

lcImage = poFbc.BarcodeImage(upper(alltrim(Labels.Part)))
COPY FILE (lcImage) TO (JUSTFNAME(lcImage))

I copy the image file generated in the current directory and scan the image with the following online scanners:

. http://www.onlinebarcodereader.com
. http://zxing.org/w/decode.jspx

In all cases the reading is in uppercase. I think you scanner is configured to return the read string to lowercase. Please check this.

Please keep me informed. Thanks for your feedback.

Luis Maria Guayan

fredkrampe  May 7, 2011 at 4:21 AM 
Hi, love the app. Very simple to use and powerful. 

But, I have a problem with Code 128 B. It only seems to generate lowercase text. That is, my TextToEncode is in uppercase, and the human readable is in uppercase, but when I actually print and scan it, the result is lower case. My code is:
===================================================
SET PROCEDURE TO LOCFILE("foxBarcode.PRG"),LOCFILE("gpImage2.prg") additive
PRIVATE poFbc
poFbc = CREATEOBJECT("FoxBarCode")
poFbc.cImageType = "PNG"
poFbc.nBarcodeType = 110
poFbc.cSet128 = "B"
poFBC.nImageHeight=203
poFBC.nResolution = 203
poFbc.nFactor = 3
poFbc.nmargin = 1

*-- Create FoxBarcode Object
REPORT FORM shiplabel TO PRINTER PROMPT PREVIEW 
=======================================================
my report image has the property poFbc.BarcodeImage(upper(alltrim(labels.part)))
though you can easily test with its equivalent poFbc.BarcodeImage("005-CHP-NSG-11-02")

Any ideas?
Thanks,
Fred

VFPEncoding  Apr 23, 2011 at 10:29 PM 
Limcarlo: see the sample forms are included with the download of FoxBarcode.

To you I need to create in your form the oFBC property and the clause where you create the instance of the FoxBarcode class with CREATEOBJETC()

Ex:
ThisForm.oFBC = CREATEOBJECT("FoxBarcode")

Luis Maria Guayan

limcarlo  Apr 23, 2011 at 9:47 AM 
Good day! 
Thank you very much for the FoxBarCode app. I'm a newbie using vfp 9. I'm using the app in printing barcode labels for items in my POS system, and it is working very well. I'm trying to include it in my ITEMs entry form as an image, and tried using the "THISFORM.Image1.Picture = THISFORM.loFbc.BarcodeImage(myVariable)". I placed the FoxBarcode script in my FORM.INIT, but when running the form it gives an error "Unknown member LOFBC". Need help thank you very much.

soykanozcelik  Apr 17, 2011 at 7:10 AM 
Would you please consider including QR Code in the near future ?

VFPEncoding  Apr 11, 2011 at 4:13 AM 
Hi montand:

What version of "FoxBarcode" are you using? That error was corrected in version 0.12 and was improved in version 0.13 (the current version is 0.14)

I'm using FoxBarcode 0.14 with VFP9 SP2 and Windows 7 64 bits without problems.

If even with the 0.14 version the problem continues, find the array "laListFontName" in "FoxBarcode.PRG" file and try changing some of the 10 names of fonts for the names of fonts you have installed on your Windows.

Ej: 
laListFontName(1) = "Calibri" && Old name = "Courier New"

Please keep me informed. Thanks for your feedback.

Luis Maria Guayan

montand  Apr 9, 2011 at 12:21 AM 
Hello folks, I've been using the Luis Maria's prg CodBar and is really good, i want to test this one but i get an error when run it in developer mode, GDI+ error GRAPHICS.DRAWSTRINGS Error code : 15 Description: Font Style not found. If press omit, error code: 2 description: Invalid Parameter
I have VFP9 SP2 in windows 7 ultimate in 64bits
I hope your comments and thanks for this excelent tools

fsinatha  Feb 17, 2011 at 9:50 AM 
Very good job. Awesome.

Faure  Jan 12, 2011 at 2:49 AM 
very very great work ! nice !
many thanks

proposal : file for localization string 

Best Regards
Francis (French MVP VFP)

thai_vfp  Nov 29, 2010 at 9:51 PM 
Thank you.

VFPEncoding  Nov 20, 2010 at 8:41 AM 
Yes, is considered the inclusion of 2D symbologies, and the first will be the PDF417, but in the future ...

edyshor  Nov 20, 2010 at 8:07 AM 
Awesome, thank you!
Would you please consider including PDF417 in the near future ?