Problem when print CODE128 using Barlib

Problem when print CODE128 using Barlib

Postby vilian » Mon Mar 05, 2018 7:54 pm

Hi Guys,

I´m having a problem when try to print barcode using Barlib.

IF I print the string 15140803532877000111550020000018651000018657 using the pattern CODE128 and after I try to read the barcode generated, the value returned is different.

Do you know why ?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 972
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: Problem when print CODE128 using Barlib

Postby Enrico Maria Giordano » Mon Mar 05, 2018 11:01 pm

Try this fixed code:

Code: Select all  Expand view
FUNCTION _CODE128( cCode, cMode )

    LOCAL aCode := {"212222",;
                    "222122",;
                    "222221",;
                    "121223",;
                    "121322",;
                    "131222",;
                    "122213",;
                    "122312",;
                    "132212",;
                    "221213",;
                    "221312",;
                    "231212",;
                    "112232",;
                    "122132",;
                    "122231",;
                    "113222",;
                    "123122",;
                    "123221",;
                    "223211",;
                    "221132",;
                    "221231",;
                    "213212",;
                    "223112",;
                    "312131",;
                    "311222",;
                    "321122",;
                    "321221",;
                    "312212",;
                    "322112",;
                    "322211",;
                    "212123",;
                    "212321",;
                    "232121",;
                    "111323",;
                    "131123",;
                    "131321",;
                    "112313",;
                    "132113",;
                    "132311",;
                    "211313",;
                    "231113",;
                    "231311",;
                    "112133",;
                    "112331",;
                    "132131",;
                    "113123",;
                    "113321",;
                    "133121",;
                    "313121",;
                    "211331",;
                    "231131",;
                    "213113",;
                    "213311",;
                    "213131",;
                    "311123",;
                    "311321",;
                    "331121",;
                    "312113",;
                    "312311",;
                    "332111",;
                    "314111",;
                    "221411",;
                    "431111",;
                    "111224",;
                    "111422",;
                    "121124",;
                    "121421",;
                    "141122",;
                    "141221",;
                    "112214",;
                    "112412",;
                    "122114",;
                    "122411",;
                    "142112",;
                    "142211",;
                    "241211",;
                    "221114",;
                    "213111",;
                    "241112",;
                    "134111",;
                    "111242",;
                    "121142",;
                    "121241",;
                    "114212",;
                    "124112",;
                    "124211",;
                    "411212",;
                    "421112",;
                    "421211",;
                    "212141",;
                    "214121",;
                    "412121",;
                    "111143",;
                    "111341",;
                    "131141",;
                    "114113",;
                    "114311",;
                    "411113",;
                    "411311",;
                    "113141",;
                    "114131",;
                    "311141",;
                    "411131",;
                    "211412",;
                    "211214",;
                    "211232",;
                    "2331112"}

    LOCAL nSum, cBar, cCar
    LOCAL cTemp, n, nCAr, nCount := 0
    LOCAL lCodeC := .F., lCodeA := .F.

    IF VALTYPE( cCode ) != "C" THEN RETURN NIL

    IF !EMPTY( cMode )
        IF VALTYPE( cMode ) = "C" .AND. UPPER( cMode ) $ "ABC"
            cMode = UPPER( cMode )
        ENDIF
    ENDIF

    IF EMPTY( cMode )
        IF ISNUMBER( cCode )
            lCodeC = .T.
            cTemp  = aCode[ 106 ]
            nSum   = 105
        ELSE
            FOR n = 1 TO LEN( cCode )
                nCount += IF( SUBSTR( cCode, n, 1 ) > 31, 1, 0 )
            NEXT

            IF nCount < LEN( cCode ) / 2
                lCodeA = .T.
                cTemp  = aCode[ 104 ]
                nSum   = 103
            ELSE
                cTemp = aCode[ 105 ]
                nSum  = 104
            ENDIF
        ENDIF
    ELSE
        IF cMode = "C"
            lCodeC = .T.
            cTemp  = aCode[ 106 ]
            nSum   = 105
        ELSEIF cMode = "A"
            lCodeA = .T.
            cTemp  = aCode[ 104 ]
            nSum   = 103
        ELSE
            cTemp = aCode[ 105 ]
            nSum  = 104
        ENDIF
    ENDIF

    nCount = 0

    FOR n = 1 TO LEN( cCode )
        nCount++
        cCar = SUBSTR( cCode, n, 1 )

        IF lCodeC
            IF LEN( cCode ) = n
                CTemp += aCode[ 101 ]
                nSum += 100 * nCount
                nCount++
                nCar = ASC( cCar ) - 31
            ELSE
                nCar = VAL( SUBSTR( cCode, n, 2 ) ) + 1
                n++
            ENDIF
        ELSEIF lCodeA
            IF cCar > "_"
                cTemp += aCode[ 101 ]
                nCar = ASC( cCar ) - 31
            ELSEIF cCar <= " "
                nCar = ASC( cCar ) + 64
            ELSE
                nCar = ASC( cCar ) - 31
            ENDIF
        ELSE
            IF cCar <= " "
                cTemp += aCode[ 102 ]
                nCar = ASC( cCar ) + 64
            ELSE
                nCar = ASC( cCar ) - 31
            ENDIF
        ENDIF

        nSum += ( nCar - 1 ) * nCount
        cTemp = cTemp + aCode[ nCar ]
    NEXT

    nSum  = nSum % 103 + 1
    cTemp = cTemp + aCode[ nSum ] + aCode[ 107 ]
    cBar  = ""

    FOR n = 1 TO LEN( cTemp ) STEP 2
        cBar += REPLICATE( "1", VAL( SUBSTR( cTemp, n, 1 ) ) )
        cBar += REPLICATE( "0", VAL( SUBSTR( cTemp, n + 1, 1 ) ) )
    NEXT

    RETURN cBar


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Problem when print CODE128 using Barlib

Postby vilian » Tue Mar 06, 2018 11:39 am

Hi Enrico,

Don't work yet :(
I made a little sample:
Code: Select all  Expand view
  PRINT oPrn NAME "Teste Barcode" PREVIEW
   oPrn:SetPortrait()

   PAGE
      aMargin:=oPrn:SizeInch2Pix(1,1)
    Code128(aMargin[2],aMargin[1],"15140803532877000111550020000018651000018657",oPrn,"C",0,.T.,0.029,1.20)

   ENDPAGE

   PrintEnd()
 


When I read the barcode that is printed, the number returned is 15140803531118000111550020000018651000018657
The part that is returning different is '1118' that is bold/red in the string.
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 972
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: Problem when print CODE128 using Barlib

Postby Enrico Maria Giordano » Wed Mar 07, 2018 1:53 pm

You are right! There was a wrong code. This is the fixed version:

Code: Select all  Expand view
FUNCTION _CODE128( cCode, cMode )

    LOCAL aCode := {"212222",;
                    "222122",;
                    "222221",;
                    "121223",;
                    "121322",;
                    "131222",;
                    "122213",;
                    "122312",;
                    "132212",;
                    "221213",;
                    "221312",;
                    "231212",;
                    "112232",;
                    "122132",;
                    "122231",;
                    "113222",;
                    "123122",;
                    "123221",;
                    "223211",;
                    "221132",;
                    "221231",;
                    "213212",;
                    "223112",;
                    "312131",;
                    "311222",;
                    "321122",;
                    "321221",;
                    "312212",;
                    "322112",;
                    "322211",;
                    "212123",;
                    "212321",;
                    "232121",;
                    "111323",;
                    "131123",;
                    "131321",;
                    "112313",;
                    "132113",;
                    "132311",;
                    "211313",;
                    "231113",;
                    "231311",;
                    "112133",;
                    "112331",;
                    "132131",;
                    "113123",;
                    "113321",;
                    "133121",;
                    "313121",;
                    "211331",;
                    "231131",;
                    "213113",;
                    "213311",;
                    "213131",;
                    "311123",;
                    "311321",;
                    "331121",;
                    "312113",;
                    "312311",;
                    "332111",;
                    "314111",;
                    "221411",;
                    "431111",;
                    "111224",;
                    "111422",;
                    "121124",;
                    "121421",;
                    "141122",;
                    "141221",;
                    "112214",;
                    "112412",;
                    "122114",;
                    "122411",;
                    "142112",;
                    "142211",;
                    "241211",;
                    "221114",;
                    "413111",;
                    "241112",;
                    "134111",;
                    "111242",;
                    "121142",;
                    "121241",;
                    "114212",;
                    "124112",;
                    "124211",;
                    "411212",;
                    "421112",;
                    "421211",;
                    "212141",;
                    "214121",;
                    "412121",;
                    "111143",;
                    "111341",;
                    "131141",;
                    "114113",;
                    "114311",;
                    "411113",;
                    "411311",;
                    "113141",;
                    "114131",;
                    "311141",;
                    "411131",;
                    "211412",;
                    "211214",;
                    "211232",;
                    "2331112"}

    LOCAL nSum, cBar, cCar
    LOCAL cTemp, n, nCAr, nCount := 0
    LOCAL lCodeC := .F., lCodeA := .F.

    IF VALTYPE( cCode ) != "C" THEN RETURN NIL

    IF !EMPTY( cMode )
        IF VALTYPE( cMode ) = "C" .AND. UPPER( cMode ) $ "ABC"
            cMode = UPPER( cMode )
        ENDIF
    ENDIF

    IF EMPTY( cMode )
        IF ISNUMBER( cCode )
            lCodeC = .T.
            cTemp  = aCode[ 106 ]
            nSum   = 105
        ELSE
            FOR n = 1 TO LEN( cCode )
                nCount += IF( SUBSTR( cCode, n, 1 ) > 31, 1, 0 )
            NEXT

            IF nCount < LEN( cCode ) / 2
                lCodeA = .T.
                cTemp  = aCode[ 104 ]
                nSum   = 103
            ELSE
                cTemp = aCode[ 105 ]
                nSum  = 104
            ENDIF
        ENDIF
    ELSE
        IF cMode = "C"
            lCodeC = .T.
            cTemp  = aCode[ 106 ]
            nSum   = 105
        ELSEIF cMode = "A"
            lCodeA = .T.
            cTemp  = aCode[ 104 ]
            nSum   = 103
        ELSE
            cTemp = aCode[ 105 ]
            nSum  = 104
        ENDIF
    ENDIF

    nCount = 0

    FOR n = 1 TO LEN( cCode )
        nCount++
        cCar = SUBSTR( cCode, n, 1 )

        IF lCodeC
            IF LEN( cCode ) = n
                CTemp += aCode[ 101 ]
                nSum += 100 * nCount
                nCount++
                nCar = ASC( cCar ) - 31
            ELSE
                nCar = VAL( SUBSTR( cCode, n, 2 ) ) + 1
                n++
            ENDIF
        ELSEIF lCodeA
            IF cCar > "_"
                cTemp += aCode[ 101 ]
                nCar = ASC( cCar ) - 31
            ELSEIF cCar <= " "
                nCar = ASC( cCar ) + 64
            ELSE
                nCar = ASC( cCar ) - 31
            ENDIF
        ELSE
            IF cCar <= " "
                cTemp += aCode[ 102 ]
                nCar = ASC( cCar ) + 64
            ELSE
                nCar = ASC( cCar ) - 31
            ENDIF
        ENDIF

        nSum += ( nCar - 1 ) * nCount
        cTemp = cTemp + aCode[ nCar ]
    NEXT

    nSum  = nSum % 103 + 1
    cTemp = cTemp + aCode[ nSum ] + aCode[ 107 ]
    cBar  = ""

    FOR n = 1 TO LEN( cTemp ) STEP 2
        cBar += REPLICATE( "1", VAL( SUBSTR( cTemp, n, 1 ) ) )
        cBar += REPLICATE( "0", VAL( SUBSTR( cTemp, n + 1, 1 ) ) )
    NEXT

    RETURN cBar


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Problem when print CODE128 using Barlib

Postby vilian » Wed Mar 07, 2018 3:06 pm

I tried with the new code, but still not working here :(
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 972
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: Problem when print CODE128 using Barlib

Postby Enrico Maria Giordano » Wed Mar 07, 2018 3:10 pm

Double check that you are using the new code, please. It works fine here now with your sample. Maybe you need this function:

Code: Select all  Expand view
FUNCTION ISNUMBER( cStr )

    LOCAL i

    FOR i = 1 TO LEN( cStr )
        IF !ISDIGIT( SUBSTR( cStr, i, 1 ) ) THEN RETURN .F.
    NEXT

    RETURN .T.


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Problem when print CODE128 using Barlib

Postby vilian » Wed Mar 07, 2018 5:29 pm

Enrico,

You are right. I was doing "IsNumber" by a wrong way. Everything is fine now.
Thank you very much ;)
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 972
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: Problem when print CODE128 using Barlib

Postby jds » Tue Feb 12, 2019 10:29 am

Hallo,
Where can I find the barlib library?
José
jds
 
Posts: 122
Joined: Sat Dec 05, 2009 12:44 pm

Re: Problem when print CODE128 using Barlib

Postby jds » Mon Mar 18, 2019 3:22 pm

vilian wrote:Enrico,

You are right. I was doing "IsNumber" by a wrong way. Everything is fine now.
Thank you very much ;)


Hi Vilian
Can you send me the complete program to print code 128 starting from any number or name
Do you use barlib.lib or barlib32.lib and barcode.ch
Where do you position the .lib and the .ch (in fwh or harbour map)
Thank you
deschutterjose@gmail.com
jds
 
Posts: 122
Joined: Sat Dec 05, 2009 12:44 pm

Re: Problem when print CODE128 using Barlib

Postby Otto » Mon Mar 18, 2019 10:30 pm

Hello,
May I ask why you don't use FIVEWIN’s build in EASYREPORT?

You read what you print.
15140803532877000111550020000018651000018657
Get Outlook for Android


Best regards
Otto

Image

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6312
Joined: Fri Oct 07, 2005 7:07 pm

Re: Problem when print CODE128 using Barlib

Postby nageswaragunupudi » Tue Mar 19, 2019 2:55 am

The built-in barcode functionality of EasyReport can also be used directly using Printer class with this code:
Code: Select all  Expand view
function printbarcode()

   local oPrn, oBarcode
   local cText := "FiveTechSoft"

   cText := "15140803532877000111550020000018651000018657"

   PRINT oPrn PREVIEW
   oPrn:SetLandScape()
   PAGE

      oBarCode := FWER_BarCode():New( oPrn:hDCOut, cText, 700,100, 3000, 400, 3 )
      WITH OBJECT oBarCode
         :nBCodeType    := 3  // CODE 128
         :nPinWidth     := 10
         :ShowBarCode()
      END

   ENDPAGE
   ENDPRINT

return nil
 

Using the same barcode class that FWH EasyReport uses.
This class is already available in FWH. You do not need any external library.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Problem when print CODE128 using Barlib

Postby jds » Tue Mar 19, 2019 8:15 am

nageswaragunupudi wrote:The built-in barcode functionality of EasyReport can also be used directly using Printer class with this code:
Code: Select all  Expand view
function printbarcode()

   local oPrn, oBarcode
   local cText := "FiveTechSoft"

   cText := "15140803532877000111550020000018651000018657"

   PRINT oPrn PREVIEW
   oPrn:SetLandScape()
   PAGE

      oBarCode := FWER_BarCode():New( oPrn:hDCOut, cText, 700,100, 3000, 400, 3 )
      WITH OBJECT oBarCode
         :nBCodeType    := 3  // CODE 128
         :nPinWidth     := 10
         :ShowBarCode()
      END

   ENDPAGE
   ENDPRINT

return nil
 

Using the same barcode class that FWH EasyReport uses.
This class is already available in FWH. You do not need any external library.



Is Easyreport also included in my 9.0 version of FWHarbour?
José (jds)
jds
 
Posts: 122
Joined: Sat Dec 05, 2009 12:44 pm

Re: Problem when print CODE128 using Barlib

Postby nageswaragunupudi » Tue Mar 19, 2019 8:19 am

What is 9.0 version?

Did you try the above code?
If it works for you, then the Easy Report runtime is included in your version.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Problem when print CODE128 using Barlib

Postby Marc Venken » Tue Mar 19, 2019 9:39 am

[quote="nageswaragunupudi"]The built-in barcode functionality of EasyReport can also be used directly using Printer class with this code:
Code: Select all  Expand view
function printbarcode()

   local oPrn, oBarcode
   local cText := "FiveTechSoft"

   cText := "15140803532877000111550020000018651000018657"

   PRINT oPrn PREVIEW
   oPrn:SetLandScape()
   PAGE

      oBarCode := FWER_BarCode():New( oPrn:hDCOut, cText, 700,100, 3000, 400, 3 )
      WITH OBJECT oBarCode
         :nBCodeType    := 3  // CODE 128
         :nPinWidth     := 10
         :ShowBarCode()
      END

   ENDPAGE
   ENDPRINT

return nil
 


Where is this function located ? :

FWER_BarCode():New( oPrn:hDCOut, cText, 700,100, 3000, 400, 3 )
Looking for the options that exist for :

 :nBCodeType    := 3  // CODE 128
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Problem when print CODE128 using Barlib

Postby nageswaragunupudi » Tue Mar 19, 2019 9:41 am

Available from FWH 18.05 onwards.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 91 guests

cron