FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour codigo de barras 128C... otra vez
Posts: 5
Joined: Wed Jul 07, 2010 11:08 PM
codigo de barras 128C... otra vez
Posted: Wed Jul 14, 2010 12:30 AM

Hola,

Aqui tengo una funcion en VB que hace la supuesta transformacion de la cadena de texto a una ca<dena que se puede usar para ponerle un codigo de barras 120c.

Si alguien tiene tiempo y el conocimiento y la puede desifrar se los agradeceria:

Un ejemplo seria este:

Esta cadena 01032001001400 convertida seria esto : ÍÂ!H&zÎ

La funcion en VB es esta:

Public Function Code128c(ByVal DataToEncode As String, Optional ByVal ReturnType As Integer = 0) As String

Dim I As Integer
Dim j As Integer
Dim F As Integer
Dim DataToPrint As String
Dim OnlyCorrectData As String
Dim PrintableString As String
Dim Encoding As String
Dim WeightedTotal As Long
Dim WeightValue As Integer
Dim CurrentValue As Long
Dim CheckDigitValue As Integer
Dim Factor As Integer
Dim CheckDigit As Integer
Dim CurrentEncoding As String
Dim NewLine As String
Dim Msg As String
Dim CurrentChar As String
Dim CurrentCharNum As Integer
Dim C128_StartA As String
Dim C128_StartB As String
Dim C128_StartC As String
Dim C128_Stop As String
Dim C128Start As String
Dim C128CheckDigit As String
Dim StartCode As String
Dim StopCode As String
Dim Fnc1 As String
Dim LeadingDigit As Integer
Dim EAN2AddOn As String
Dim EAN5AddOn As String
Dim EANAddOnToPrint As String
Dim HumanReadableText As String
Dim StringLength As Integer
Dim CorrectFNC As Integer
Dim CID As Integer
Dim FID As Integer
Dim NCID As Integer


    NCID = 0
    FID = 0
    If ReturnType = 6 Or ReturnType = 7 Then NCID = 12000
    If ReturnType = 8 Then NCID = 11300
    If ReturnType = 9 Then NCID = 11500
    If ReturnType = 6 Or ReturnType = 9 Then FID = 11500
    If ReturnType = 7 Or ReturnType = 8 Then FID = 11300
    If ReturnType &lt;&gt; 0 And ReturnType &lt;&gt; 1 And ReturnType &lt;&gt; 2 Then ReturnType = 0
    PrintableString = &quot;&quot;
    OnlyCorrectData = &quot;&quot;
    StringLength = Len(DataToEncode)
    For I = 1 To StringLength
        If IsNumeric(Mid(DataToEncode, I, 1)) Then OnlyCorrectData = OnlyCorrectData &amp; Mid(DataToEncode, I, 1)
    Next I
    DataToEncode = OnlyCorrectData
    If (Len(DataToEncode) Mod 2) = 1 Then DataToEncode = &quot;0&quot; &amp; DataToEncode
    PrintableString = ChrW(205 + FID)
    WeightedTotal = 105
    WeightValue = 1
    StringLength = Len(DataToEncode)
    For I = 1 To StringLength Step 2
        CurrentValue = val(Mid(DataToEncode, I, 2))
        If CurrentValue &lt; 95 And CurrentValue &gt; 0 Then PrintableString = PrintableString &amp; ChrW(CurrentValue + 32 + NCID)
        If CurrentValue &gt; 94 Then PrintableString = PrintableString &amp; ChrW(CurrentValue + 100 + NCID)
        If CurrentValue = 0 Then PrintableString = PrintableString &amp; ChrW(194 + NCID)
        CurrentValue = CurrentValue * WeightValue
        WeightedTotal = WeightedTotal + CurrentValue
        WeightValue = WeightValue + 1
        If ChrW(CurrentValue + 32 + NCID) = &quot;'&quot; Then PrintableString = PrintableString &amp; &quot;'&quot;
        Next I
    CheckDigitValue = (WeightedTotal Mod 103)
    If CheckDigitValue &lt; 95 And CheckDigitValue &gt; 0 Then C128CheckDigit = ChrW(CheckDigitValue + 32 + FID)
    If CheckDigitValue &gt; 94 Then C128CheckDigit = ChrW(CheckDigitValue + 100 + FID)
    If CheckDigitValue = 0 Then C128CheckDigit = ChrW(194 + FID)
    If ReturnType = 0 Or ReturnType &gt; 2 Then Code128c = PrintableString &amp; C128CheckDigit &amp; ChrW(206 + FID)
    If ReturnType = 1 Then Code128c = DataToEncode &amp; CheckDigitValue
    If ReturnType = 2 Then Code128c = Str(CheckDigitValue)

End Function

Continue the discussion