office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Access使用128條碼字體生成Code128C條碼

2010-10-13 03:26:49
zhuyiwen-Office交流網
原創
5200
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




分享