Options

How to create a bar code label printing report

ShenpenShenpen Member Posts: 386
edited 2005-09-24 in NAV Tips & Tricks
It is the hardest suffering I had in this year, so I would like to share it.

First, forget bar code fonts (do not work for non-English countries, it is a deep Navision bug of what fonts it accept).

Use the BMP-generating download from the downloads.

You will need to print more than one barcode per item, so you will need a new table, with fields like Item No., Barcode, Barcode BMP (a BLOB), Quantity, Price, Description, etc. of which Barcode (f.e. Item Cross-References) and Quantity is important now - quantity is where users enter how much to print from a given item (and of course you need additional code that suggests to print the quantities on inventory or a receipt or manuf. document etc., but that's easy to do)

Create a directory C:\barcode. Of course you can create fields in some settings table, but for this example I will hardcode it.

the barcode generating and importing code (on a button, or something) will look something like:


fname:='c:\barcode\barcodetemp.bmp';

CLEAR(itemlabel);
CREATE(shl);
    
  IF itemlabel.FIND('-') THEN REPEAT
  bc:=itemlabel."Barcode No.";
  IF STRLEN(bc)=13 THEN BEGIN
    bc:=COPYSTR(bc,1,12);
    zero:=0;
    tru:=TRUE;
    shl.Run('c:\barcode\NAVIBAR.exe ' + bc +'{01{120{60{'+fname,zero,tru);
    
    itemlabel."Barcode BMP".IMPORT(fname);
    itemlabel.MODIFY(TRUE);
    FILE.ERASE(fname);
      END ELSE BEGIN
    itemlabel.DELETE(TRUE);
  END;
UNTIL itemlabel.NEXT=0;

CLEAR(shl);

COMMIT;
rep.SETTABLEVIEW(itemlabel);
rep.RUN;


highlights:

- this is for EAN13. the STRLEN-tricks are to ensure only 13 digit barcodes will be printed, but we export only 12, because Navibar autocalculates the check digit, so even if it's wrong in Navision, it can print it. (Of course reading it will not be possible, as you don't have such code. Okay, it may be a bit clumsy solution, but I did not want to add error messages.)

shl is an Automation, "Windows Scripting Host Object Library.Shell

it is configured by the two variables, to hold up everything until the program finishes running. It is important, or else you try reading a file that is locked and that is not possible.

Then we run the report. The report will be the next post.

Do It Yourself is they key. Standard code might work - your code surely works.

Comments

  • Options
    ShenpenShenpen Member Posts: 386
    The report is really hard.

    You can start with a report wizard, that at least can easily configure the layout.

    You will need the record count in you OnPreDataItem>
    NoOfRecords:=0;
    CLEAR(iltocount);
    iltocount.COPYFILTERS(IL);
    IF iltocount.FIND('-') THEN REPEAT
       NoOfRecords+=iltocount.Quantity;
    UNTIL iltocount.NEXT=0;
    

    First thing is to create an Integer data item, indented. You will need
    SETRANGE(Number,1,IL.Quantity);
    
    in the OnPreDataItem of integer. Do not forget to copy the OnPreSection!

    OnAfterGetRecord of Integer for a 3-column report is something like:
    RecordNo := RecordNo + 1;
    ColumnNo := ColumnNo + 1;
    
    IL.CALCFIELDS("Barcode BMP");
    
    IF ColumnNo=1 THEN BEGIN
       il1.COPY(IL);
       il1.CALCFIELDS("Barcode BMP");
    END;
    
    IF ColumnNo=2 THEN BEGIN
      il2.COPY(IL);
      il2.CALCFIELDS("Barcode BMP");
    END;
    
    IF ColumnNo=3 THEN BEGIN
      il3.COPY(IL);
      il3.CALCFIELDS("Barcode BMP");
    END;
    
    
    Addr[ColumnNo][1] := FORMAT(IL."Item No.");
    Addr[ColumnNo][2] := FORMAT(IL."Variant Code");
    
    Addr[ColumnNo][3] := FORMAT(IL."Item Description");
    Addr[ColumnNo][4] := FORMAT(IL."Price"); //and maybe the currency
    
    IF RecordNo = NoOfRecords THEN BEGIN
      FOR i := ColumnNo + 1 TO NoOfColumns DO
        CLEAR(Addr[i]);
        //CLEAR(il1);
        //CLEAR(il2);
        //CLEAR(il3); // there is some bug here, so commented out
      ColumnNo := 0;
    END ELSE BEGIN
      IF ColumnNo = NoOfColumns THEN
        ColumnNo := 0;
    END;
    
    

    I don't even try to explain it. Some of it is standard, wizard-generated code, the other is working around Navision's limitation that it cannot print a BMP from a variable, so we trick with record variables. OF course you need picture boxes with sourceexpr like il1."Barcode BMP", and so on.

    There is a bug somewhere near the commented out code, it prints two extra labels, only with picture, no text. This is not a serious problem, I am tired now, but I will try making a 3-array of record variable instead of IL1, IL2, IL3 record variables, maybe that corrects that.

    Maybe with this help barcode printing won't become a big nightmare for you.

    Do It Yourself is they key. Standard code might work - your code surely works.
Sign In or Register to comment.