IF IsNumber( as_Barcode ) Then
IF Mod( Len( as_Barcode ), 2 ) = 0 Then
ls_Start = ls_StartC
Else
ls_Start = ls_StartB
End IF
Else
ls_Start = ls_StartB
End IF
Choose Case ls_Start
Case ls_StartB //code128B編碼方式
li_Length = Len( as_Barcode )
li_WeightTotal = Asc( ls_StartB ) - 100
For li_Count = 1 To li_Length
li_Temp = Asc( Mid( as_Barcode, li_Count, 1 ) )
IF li_Temp >= 32 Then
li_WeightTotal += ( li_Temp - 32 ) * li_Count
Else
li_WeightTotal += ( li_Temp + 64 ) * li_Count
End IF
Next
li_EndAsc = Mod( li_WeightTotal, 103 )
IF li_EndAsc >= 95 Then
li_EndAsc += 100
Else
li_EndAsc += 32
End IF
ls_EndChar = Char( li_EndAsc )
ls_Temp = as_Barcode
Case ls_StartC
li_Length = Integer( Len( as_Barcode ) / 2 )
li_WeightTotal = Asc( ls_StartC ) - 100
For li_Count = 1 To li_Length
li_Temp = Integer( Mid( as_Barcode, li_Count * 2 - 1, 2 ) )
li_WeightTotal += li_Temp * li_Count
Next
li_EndAsc = Mod( li_WeightTotal, 103 )
If li_EndAsc >= 95 Then
li_EndAsc += 100
Else
li_EndAsc += 32
End If
ls_EndChar = Char( li_EndAsc )
For li_Count = 1 To li_Length
li_Temp = Integer( Mid( as_Barcode, li_Count * 2 - 1, 2 ) )
IF li_Temp >= 95 Then
ls_Temp = ls_Temp + Char( li_Temp + 100 )
Else
ls_Temp = ls_Temp + Char( li_Temp + 32 )
End IF
Next