vb.net 使用code128 代码

 public static string To128Code(this String inputData)
        {
            string result;
            Int64 checksum = 104;
            for (int ii = 0; ii <= inputData.Length - 1; ii++)
            {

                if ((int)inputData[ii] >= 32)
                {
                    checksum += ((int)inputData[ii] - 32) * (ii + 1);
                }
                else
                {
                    checksum += ((int)inputData[ii] + 64) * (ii + 1);
                }
            }
            checksum = checksum % 103;
            if (checksum < 95)
            {
                checksum += 32;
            }
            else
            {
                checksum += 100;
            }
            result = Convert.ToChar(204) + inputData.ToString() + Convert.ToChar(checksum) + Convert.ToChar(206);
            return result;
        }

#Region "生成Code128字符集" Public Function Get128CodeString(ByVal inputData As String) As String Dim result As String Dim checksum As Int64 = 104 For ii As Integer = 0 To inputData.Length - 1 If Asc(inputData(ii)) >= 32 Then checksum += (Asc(inputData(ii)) - 32) * (ii + 1) Else checksum += (Asc(inputData(ii)) + 64) * (ii + 1) End If Next checksum = checksum Mod 103 If checksum < 95 Then checksum += 32 Else checksum += 100 End If result = Convert.ToChar(204) + inputData.ToString() + Convert.ToChar(checksum) + Convert.ToChar(206) Return result End Function#End Region

你可能感兴趣的:(.Net)