1. 程式人生 > >CODE39和CODE128編碼生成函式(VBA版)

CODE39和CODE128編碼生成函式(VBA版)

Public Function StrToCode39(str As String) As String

    StrToCode39 = "*" & str & "*"
   
End Function


Function StrToCode128(str As String) As String
    Dim l As Integer, i As Integer, n As Integer, t As Integer, s As Integer
    Dim p As String
    l = Len(str)
    n = 104
    For i = 1 To l
        t = Asc(Mid(str, i, 1))
        If t >= 32 Then
            n = n + (t - 32) * i
        Else
            n = n + (t + 64) * i
        End If
    Next i
    s = n Mod 103
    If s >= 95 Then
        s = s + 100
    Else
        s = s + 32
    End If
    StrToCode128 = ChrW(204) + str + ChrW(s) + ChrW(206)
   
End Function