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
|
Coding sample |
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: |
||||||||||||||||||||
|
||||||||||||||||||||
' 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. |
||||||||||||||||||||
'
|
||||||||||||||||||||
Dim J, N, P As Integer | ||||||||||||||||||||
' On Error GoTo ErrorHandlingCheckDigit1110 | ||||||||||||||||||||
P = 10 | ||||||||||||||||||||
If Mode = 0 Then N = Len(NumStringIn) - 1 Else N = Len(NumStringIn) | ' (1) | |||||||||||||||||||
For J = 1 To N | ' (2) | |||||||||||||||||||
P = P + Mid(NumStringIn, J, 1) | ' (3),(4) | |||||||||||||||||||
If P > 10 Then P = P - 10 | ' (5) | |||||||||||||||||||
P = P * 2 | ||||||||||||||||||||
If P >= 11 Then P = P - 11 | ' (6) | |||||||||||||||||||
Next J | ||||||||||||||||||||
Select Case Mode | ||||||||||||||||||||
Case 0 | ' validating | |||||||||||||||||||
P = P + Mid(NumStringIn, N + 1, 1) | ' (4) | |||||||||||||||||||
If P > 10 Then P = P - 10 | ||||||||||||||||||||
CheckDigit1110 = (P = 1) | ||||||||||||||||||||
Case 1, 2 | ' calculating check digits | |||||||||||||||||||
P = 11 - P | ||||||||||||||||||||
If P = 10 Then P = 0 | ||||||||||||||||||||
If Mode = 1 Then CheckDigit1110 = NumStringIn & P Else CheckDigit1110 = P | ' (4) | |||||||||||||||||||
Case Else | ' improper entry | |||||||||||||||||||
CheckDigit1110 = "" | ||||||||||||||||||||
End Select | ||||||||||||||||||||
' Exit Function | ||||||||||||||||||||
' ErrorHandlingCheckDigit1110: | ||||||||||||||||||||
' Debug.Print "Unexpected error in CheckDigit1110: " & Err | ' error handling | |||||||||||||||||||
' Debug.Print "Mode=" & Mode & " - NumStringIn=" & NumStringIn | ||||||||||||||||||||
' CheckDigit1110 = "" | ||||||||||||||||||||
' Exit Function | ||||||||||||||||||||
' | ||||||||||||||||||||
' Notes: | ||||||||||||||||||||
|
||||||||||||||||||||
' | ||||||||||||||||||||
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:
Disclaimer | Copyright | last revision: 26.11.2000 01:02 |