Access使用128条码字体生成Code128C条码

2010-10-13 03:26:49
zhuyiwen-Office交流网
原创
654
Function ToCode128C(ByVal s As String) As String ' zhuyiwen 2010.10.12 ' 使用code128.ttf字体生成Code128C条码
    
    
    Dim ns As String
    Dim total As Long
    If Len(s) > 0 And IsNumeric(s) Then total = 105 ' Start Code
    If Len(s) Mod 2 > 0 Then s = s + "0" ' 不足偶数位补0
    Dim i As Integer, l As Integer
    l = Len(s) \ 2
    For i = 0 To l - 1
        ns = ns + getChar(Mid(s, i * 2 + 1, 2))
        total = total + (i + 1) * Val(Mid(s, i * 2 + 1, 2))
    Next
    Dim checkCode As String '生成验证码
    checkCode = "" & (total Mod 103)
    ns = ChrW(205) + ns + getChar(checkCode) + ChrW(206)
    ToCode128C = ns
    
End Function
Function getChar(ByVal s As String) As String
    
    
    Dim c As Integer
    c = Val(s)
    If c = 0 Then
        getChar = " "
    ElseIf c < 95 Then
        getChar = Chr(Asc("!") + c - 1)
    Else
        getChar = ChrW(100 + c)
    End If
End Function




分享