D.Roos, J.Kardoeus: ISO7064-standardised Check Digits Applied to Blood Bag Numbers release 1.1.1i (draft)

ISO7064-standardised Check Digits Applied to Blood Bag Numbers
Purpose
Blood product bag numbers
MOD11,10 algorithm
Calculation and validation examples
Coding sample
Hints to users
Hints to developers
References, copyright, disclaimer
 

 
Coding sample

Caution! - Code!
This section can be skipped by readers, who are not involved in software development

The function procedure as follows calculates and validates MOD11,10 check digits. 

Function CheckDigit1110 (NumStringIn As String, Mode As Integer)
'
' Purpose:
' Calculation and validateion of check digits according to MOD11,10 algorithm (DIN/ISO 7064).
' The procedure is branched for different purposes as controlled by the "mode" argument:
' 0: Validates NumStringIn and returns the result TRUE for valid or FALSE for invalid (data type: system-dependent boolean or integer).
' 1: Calculates check digit for NumStringIn, concatenates  NumStringIn and check digit and returns the concatenated result. (data type: string).
' 2: Calculates check digit for NumStringIn and returns check digit. (data type: integer).
' Die Werte der Argumente werden in der Prozedur nicht verändert.
'
' Developed by:
' Dieter Roos, Joachim Kardoeus
' References:
' Deutsches Institut fuer Normung (Hrsg.): DIN ISO 7064, Beuth Verlag GmbH, Berlin 1984
'
' Developed and tested for
' - Microsoft Access
' - Microsoft Excel
' - Microsoft Visual Basic
' and compatible environments.
'
' Required operators and functions:
' + arithmetic addition
' & string concatenatin
' Len(..) returns count of characters in a string
' Mid(a,b,c) returns substring from string a of length c beginning at position b
' Variable:
' J loop index for recursion
' N length of string to be processed
' P intermediate results in recursion
Dim J, N, P As Integer blank.gif (807 Byte)
' On Error GoTo ErrorHandlingCheckDigit1110 blank.gif (807 Byte)
P = 10 blank.gif (807 Byte)
If Mode = 0 Then N = Len(NumStringIn) - 1 Else N = Len(NumStringIn) ' (1)
For J = 1 To N ' (2)
blank.gif (807 Byte) P = P + Mid(NumStringIn, J, 1) ' (3),(4)
blank.gif (807 Byte) If P > 10 Then P = P - 10 ' (5)
blank.gif (807 Byte) P = P * 2 blank.gif (807 Byte)
blank.gif (807 Byte) If P >= 11 Then P = P - 11 ' (6)
Next J blank.gif (807 Byte)
Select Case Mode blank.gif (807 Byte)
Case 0 ' validating
blank.gif (807 Byte) P = P + Mid(NumStringIn, N + 1, 1) ' (4)
blank.gif (807 Byte) If P > 10 Then P = P - 10 blank.gif (807 Byte)
blank.gif (807 Byte) CheckDigit1110 = (P = 1) blank.gif (807 Byte)
Case 1, 2 ' calculating check digits
blank.gif (807 Byte) P = 11 - P blank.gif (807 Byte)
blank.gif (807 Byte) If P = 10 Then P = 0 blank.gif (807 Byte)
blank.gif (807 Byte) If Mode = 1 Then CheckDigit1110 = NumStringIn & P Else CheckDigit1110 = P ' (4)
Case Else ' improper entry
blank.gif (807 Byte) CheckDigit1110 = "" blank.gif (807 Byte)
End Select blank.gif (807 Byte)
' Exit Function blank.gif (807 Byte)
' ErrorHandlingCheckDigit1110: blank.gif (807 Byte)
' Debug.Print "Unexpected error in CheckDigit1110: " & Err ' error handling
' Debug.Print "Mode=" & Mode & " - NumStringIn=" & NumStringIn blank.gif (807 Byte)
' CheckDigit1110 = "" blank.gif (807 Byte)
' Exit Function blank.gif (807 Byte)
'
' Notes:
' (1) When validating the recursion has to terminate after processing the second last digit of input string.
' (2) When migrating to a different environment, make sure, that recursion does not start for n<=0 (that is terminating loop condition must be evaluated before top of loop) or reject nullstring as function input.
' (3) Assuming that position of first character in string is defined as 1.
' (4) When migrating to environments, which do not support automated data type conversion, you must apply appropriate converter functions.
'
End Function

The source code is available as ASCII-Textdatei. For best transparency and dependency on environment the sample code is restricted to the essential algorithmic steps of check digit procedure. Opportunities to reduce CPU load under specific conditions are neglegted and may be requested from the authors if necessary. Error handling is described marginal and has to be enhanced according to the specific environment.

Suggestions for migration to other development environments

The sample functon procedure calculates results of different data types according to the mode, namely a boolean when validating and numerical strings when calculating check digits. To migrate to platforms, which do not support data type variant function procedures, modification may be done alternatively according to developers preferences and supported data types as follows:

  1. Removement of either the branch for validation or check digit calculation if the software is designed to perform only one of both tasks. 
  2. Procedure-internal conversion and returning any result as character string.
  3. If booleans are stored as integers: Removement of program branch for mode=1 and concatenation of source string and check digit outside of the function procedure.
  4. Splitting into two different function procedures for "calculating check digits" and "validation" each of them having required code branches only and returning different data types.

nach oben nächste Seite

Disclaimer | Copyright last revision: 26.11.2000 01:02