IDAutomation C39 Mod 43 Function MAC

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 4

'*****************************************************************

' Visual Basic & VBA Functions for IDAutomation Barcode Fonts 2009
' © Copyright, 2000-2009 IDAutomation.com, Inc. All rights reserved.
' Redistribution and use of this code in source and/or binary
' forms, with or without modification, are permitted provided
' that: (1) all copies of the source code retain the above
' unmodified copyright notice and this entire unmodified
' section of text, (2) You or Your organization owns a valid
' Developer License to this product from IDAutomation.com
' and, (3) when any portion of this code is bundled in any
' form with an application, a valid notice must be provided
' within the user documentation, start-up screen or in the
' help-about section of the application that specifies
' IDAutomation.com as the provider of the Software bundled
' with the application.
'*****************************************************************

Dim DataToPrint As String


Dim OnlyCorrectData As String
Dim PrintableString As String
Dim WeightedTotal As Long
Dim CurrentValue As Long
Dim CheckDigitValue As Integer
Dim CheckDigit As Integer
Dim CurrentChar As String
Dim CurrentCharNum As Integer
Dim StringLength As Integer

'END OF DECLARACTIONS

Public Function Code39Mod43(DataToEncode As String, Optional ReturnType As


Integer = 0) As String
'Additional logic needed in case ReturnType is not correct
If ReturnType <> 0 And ReturnType <> 1 And ReturnType <> 2 Then ReturnType = 0
DataToEncode = UCase(DataToEncode)
DataToPrint = ""
OnlyCorrectData = ""
'Only pass correct data
StringLength = Len(DataToEncode)
For I = 1 To StringLength
'Get each character one at a time
CurrentCharNum = AscW(Mid(DataToEncode, I, 1))
'Get the value of CurrentChar according to MOD43
'0-9
If CurrentCharNum < 58 And CurrentCharNum > 47 Then OnlyCorrectData =
OnlyCorrectData & Mid(DataToEncode, I, 1)
'A-Z
If CurrentCharNum < 91 And CurrentCharNum > 64 Then OnlyCorrectData =
OnlyCorrectData & Mid(DataToEncode, I, 1)
'Space
If CurrentCharNum = 32 Then OnlyCorrectData = OnlyCorrectData &
Mid(DataToEncode, I, 1)
'-
If CurrentCharNum = 45 Then OnlyCorrectData = OnlyCorrectData &
Mid(DataToEncode, I, 1)
'.
If CurrentCharNum = 46 Then OnlyCorrectData = OnlyCorrectData &
Mid(DataToEncode, I, 1)
'$
If CurrentCharNum = 36 Then OnlyCorrectData = OnlyCorrectData &
Mid(DataToEncode, I, 1)
'/
If CurrentCharNum = 47 Then OnlyCorrectData = OnlyCorrectData &
Mid(DataToEncode, I, 1)
'+
If CurrentCharNum = 43 Then OnlyCorrectData = OnlyCorrectData &
Mid(DataToEncode, I, 1)
'%
If CurrentCharNum = 37 Then OnlyCorrectData = OnlyCorrectData &
Mid(DataToEncode, I, 1)
Next I
DataToEncode = OnlyCorrectData
WeightedTotal = 0
StringLength = Len(DataToEncode)
For I = 1 To StringLength
'Get each character one at a time
CurrentCharNum = AscW(Mid(DataToEncode, I, 1))
'Get the value of CurrentChar according to MOD43
'0-9
If CurrentCharNum < 58 And CurrentCharNum > 47 Then CurrentValue =
CurrentCharNum - 48
'A-Z
If CurrentCharNum < 91 And CurrentCharNum > 64 Then CurrentValue =
CurrentCharNum - 55
'Space
If CurrentCharNum = 32 Then CurrentValue = 38
'-
If CurrentCharNum = 45 Then CurrentValue = 36
'.
If CurrentCharNum = 46 Then CurrentValue = 37
'$
If CurrentCharNum = 36 Then CurrentValue = 39
'/
If CurrentCharNum = 47 Then CurrentValue = 40
'+
If CurrentCharNum = 43 Then CurrentValue = 41
'%
If CurrentCharNum = 37 Then CurrentValue = 42
'To print the barcode symbol representing a space it is necessary
'to type or print "=" (the equal character) instead of a space character.
If CurrentCharNum = 32 Then CurrentCharNum = 61
'Gather data to print
DataToPrint = DataToPrint & ChrW(CurrentCharNum)
'Add the values together
WeightedTotal = WeightedTotal + CurrentValue
Next I
'Divide the WeightedTotal by 43 and get the remainder, this is the CheckDigit
CheckDigitValue = (WeightedTotal Mod 43)
'Assign values to characters
'0-9
If CheckDigitValue < 10 Then CheckDigit = CheckDigitValue + 48
'A-Z
If CheckDigitValue < 36 And CheckDigitValue > 9 Then CheckDigit =
CheckDigitValue + 55
'Space
If CheckDigitValue = 38 Then CheckDigit = 61
'-
If CheckDigitValue = 36 Then CheckDigit = 45
'.
If CheckDigitValue = 37 Then CheckDigit = 46
'$
If CheckDigitValue = 39 Then CheckDigit = 36
'/
If CheckDigitValue = 40 Then CheckDigit = 47
'+
If CheckDigitValue = 41 Then CheckDigit = 43
'%
If CheckDigitValue = 42 Then CheckDigit = 37
'ReturnType 0 returns data formatted to the barcode font
If ReturnType = 0 Then Code39Mod43 = "!" & DataToPrint & ChrW(CheckDigit) &
"!" & " "
'ReturnType 1 returns data formatted for human readable text
If ReturnType = 1 Then Code39Mod43 = DataToPrint & ChrW(CheckDigit)
'ReturnType 2 returns the check digit for the data supplied
If ReturnType = 2 Then Code39Mod43 = ChrW(CheckDigit)
DataToEncode = ""
End Function
'*****************************************************************
' © Copyright, IDAutomation.com, Inc. All rights reserved.
' Redistribution and use of this code in source and/or binary
' forms, with or without modification, are permitted provided
' that: (1) all copies of the source code retain the above
' unmodified copyright notice and this entire unmodified
' section of text, (2) You or Your organization owns a valid
' Developer License to this product from IDAutomation.com
' and, (3) when any portion of this code is bundled in any
' form with an application, a valid notice must be provided
' within the user documentation, start-up screen or in the
' help-about section of the application that specifies
' IDAutomation.com as the provider of the Software bundled
' with the application.
'*****************************************************************

You might also like