Checksum Calculation

  • Thread starter Thread starter Steven Larsen
  • Start date Start date
S

Steven Larsen

Hi there,

I have a rather knotty problem with Microsoft Access (both
97 and 2000) that I haven't been able to resolve. I hope
that you can help me!

I'm creating an export to a physician databank which has,
of course, certain export specifications. Everthing is
pretty straight forward and is working well with the
exception of the last specification requirement, which is
a Checksum.

Please see sample submission below. The checksum
calculates all the ACSII characters in the text file
(including <LF>) then dividing this sum by 256 and the
remainder is the checksum value. The count begins with
the "HDR" string at the top of the attached file and ends
with the"TRLR" string at bottom.

My problem is that for some reason, my calculations are
not correct according the databank I'm submitting to. You
will see at the at and the end of the attached file (after
the TRLR) is "211." This is the value that the databank
wants to see for this particular submission. However, for
reasons unbeknowest to me, I get 159 if I count delimiters
(which, according to their specs, can either be null - chr
(0)- or "~", we have been using the nulls). I get 131 if
do not count delimiters in the calculation. The
documentation does not say if the delimiters are counted
or not.

If you would like to see the databanks documentation on
this, you can find it in a pdf at http://www.npdb-
hipdb.com/pubs/ICD-Query.pdf on page 105.

Here is the function I am using to calculate this:

Public Function fnChecksum(sLine As String) As Long
Dim checksum As Long, i As Integer

checksum = 0
For i = 1 To Len(sLine)
'If Mid(sLine, i, 1) <> Chr(0) Then
If Mid(sLine, i, 1) <> "~" Then
checksum = checksum + Asc(Mid(sLine, i, 1))
End If
Next i
fnChecksum = checksum
End Function

Where sLine is the entire string that populates the text
file from the HDR to the TRLR.

To get the final checksum value, first I add 324 to the
checksum (for the "TRLR" value) then I use the the mod
operator like so: checksum Mod 256
to get the final value.


I hope this makes sense and I hope that you can help.

Thanks!

Steve Larsen

The text file is below++++++++++++++++++++++++++++++++++++

~|~NPDB-Q~|~ VER: 3.00
TY1NY
HDR~230171300000369~sue7kathy~1L~R6.0~37826160~10222003~399
700000025565~administrator~
QRY~P~1~A~~~~
CERT~Renee Dengler~Director,
Credentials~7736985210~~10222003~
ISUBJ~Agarwala~Grojendra~~~M~248 Wood Glen
Lane~~Oakbrook~IL~~60521~~Bethany Hospital~~~3435 West Van
Buren Street~~Chicago~IL~~60624~~01151944~~~
DEA~AA5454788~
ISOFL~010~036-046669~IL~99~010~
GRAD~Christian Medical College~1967~
ALIAS~~~~~
SSN~126428099~
FEIN~
NPI~~
UPIN~C42881~
CUSE~BETH_000020~
TRLR~211~
 
Hi Steven,

A couple of thoughts:

1) Just to be sure: are you taking appropriate measures when writing
this file to disk to ensure that it contains only LF as a record
separator and not the usual CR+LF?

2) The guidance mentions checksumming the "data" but certainly includes
the value of the LF record separator in the example calculations. So I
reckon they also want you to include the value of the field separators
(delimiters). IOW drop the condition from inside your loop.
 
John,

Thanks for the reply, your thoughts and taking the trouble
to look at the documentation

1) Interesting about the LF as that I originally used chr
(10) only but for the heck of it I changed it to vbCRLF
and I got results much closer to what they were looking
for. Perhaps their documentation is incorrect.

2) I have tried it with and without the delimiters. Seems
to work better with then without counting them.

Thanks again and I'll keep pluggin away. Have no other
choice!

Steve
-----Original Message-----
Hi Steven,

A couple of thoughts:

1) Just to be sure: are you taking appropriate measures when writing
this file to disk to ensure that it contains only LF as a record
separator and not the usual CR+LF?

2) The guidance mentions checksumming the "data" but certainly includes
the value of the LF record separator in the example calculations. So I
reckon they also want you to include the value of the field separators
(delimiters). IOW drop the condition from inside your loop.
Hi there,

I have a rather knotty problem with Microsoft Access (both
97 and 2000) that I haven't been able to resolve. I hope
that you can help me!

I'm creating an export to a physician databank which has,
of course, certain export specifications. Everthing is
pretty straight forward and is working well with the
exception of the last specification requirement, which is
a Checksum.

Please see sample submission below. The checksum
calculates all the ACSII characters in the text file
(including <LF>) then dividing this sum by 256 and the
remainder is the checksum value. The count begins with
the "HDR" string at the top of the attached file and ends
with the"TRLR" string at bottom.

My problem is that for some reason, my calculations are
not correct according the databank I'm submitting to. You
will see at the at and the end of the attached file (after
the TRLR) is "211." This is the value that the databank
wants to see for this particular submission. However, for
reasons unbeknowest to me, I get 159 if I count delimiters
(which, according to their specs, can either be null - chr
(0)- or "~", we have been using the nulls). I get 131 if
do not count delimiters in the calculation. The
documentation does not say if the delimiters are counted
or not.

If you would like to see the databanks documentation on
this, you can find it in a pdf at http://www.npdb- hipdb.com/pubs/ICD-Query.pdf on page 105.

Here is the function I am using to calculate this:

Public Function fnChecksum(sLine As String) As Long
Dim checksum As Long, i As Integer

checksum = 0
For i = 1 To Len(sLine)
'If Mid(sLine, i, 1) <> Chr(0) Then
If Mid(sLine, i, 1) <> "~" Then
checksum = checksum + Asc(Mid(sLine, i, 1))
End If
Next i
fnChecksum = checksum
End Function

Where sLine is the entire string that populates the text
file from the HDR to the TRLR.

To get the final checksum value, first I add 324 to the
checksum (for the "TRLR" value) then I use the the mod
operator like so: checksum Mod 256
to get the final value.


I hope this makes sense and I hope that you can help.

Thanks!

Steve Larsen

The text file is below++++++++++++++++++++++++++++++++++++

~|~NPDB-Q~|~ VER: 3.00
TY1NY
HDR~230171300000369~sue7kathy~1L~R6.0~37826160~10222003~3 99
700000025565~administrator~
QRY~P~1~A~~~~
CERT~Renee Dengler~Director,
Credentials~7736985210~~10222003~
ISUBJ~Agarwala~Grojendra~~~M~248 Wood Glen
Lane~~Oakbrook~IL~~60521~~Bethany Hospital~~~3435 West Van
Buren Street~~Chicago~IL~~60624~~01151944~~~
DEA~AA5454788~
ISOFL~010~036-046669~IL~99~010~
GRAD~Christian Medical College~1967~
ALIAS~~~~~
SSN~126428099~
FEIN~
NPI~~
UPIN~C42881~
CUSE~BETH_000020~
TRLR~211~

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.
 
Back
Top