FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DISK I/O

Perform a IO checksum


A checksum is nothing more than a way to confirm that text has been sent and received with some degree of integrity -- however, it is not certain.

The following code demonstrates checking for correct checksums and how to find an error.
'----------------------------------

LOCAL FN buildWind
  WINDOW 1,"Check sum",(0,0)-(400,400),_doczoom
END FN

'----------------------------------
' This function simply takes a string
' and adds the characters together.
' If the MOD is "0000", then the check sum
' is correct and the function returns a
' _true conditions. If not, then it returns
' a false.

LOCAL FN checkSumHEX(theRec$)
  DIM a$, checkSum$
  DIM sum
  DIM i, l
  DIM result%

  sum = 0
  l = LEN(theRec$)
  b$ = "&H100"
  b = VAL(b$)

  FOR i = 1 TO l STEP 2
    a$ = MID$(theRec$,i,2)
    PRINT a$;
    a$ = "&H" + a$
    sum = sum + VAL(a$)
  NEXT
  c = sum MOD b
  checkSum$ = HEX$(c)

  LONG IF checkSum$ = "0000"
    result% = _true
  XELSE
    result% = _false
  END IF

END FN = result%

'----------------------------------

' The following are OK strings with correct checksums

'":02000002A2005A"
'":0200000280007C"
'":0200000290006C"
'":02000002B0004C"

DIM a,b,c
DIM a$,b$,c$

FN buildWind

'":02000002A2005A"
a$ = "02000002A2005A"
PRINT
c = FN checkSumHEX(a$)
PRINT
PRINT"record    = ";a$
PRINT"check sum = ";c
PRINT

'":0200000280007C"
a$ = "0200000280007C"
PRINT
c = FN checkSumHEX(a$)
PRINT
PRINT"record    = ";a$
PRINT"check sum = ";c
PRINT

'":0200000290006C"
a$ = "0200000290006C"
PRINT
c = FN checkSumHEX(a$)
PRINT
PRINT"record    = ";a$
PRINT"check sum = ";c
PRINT

'":02000002B0004C"
a$ = "02000002B0004D"                             '<--- error
PRINT
c = FN checkSumHEX(a$)
PRINT
PRINT"record    = ";a$; "   <--- ERROR"
PRINT"check sum = ";c
PRINT

INPUT"Enter anything to end";a$

END
Tedd