ASC Function Programming Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
'This example uses the ASC function to calculate a hash value--an
'index value for a table or file--from a string.
CONST HASHTABSIZE = 101
CLS 'Clear the screen.
INPUT "Enter a name: ",Nm$ 'Prompt for input.
TmpVal = 0
FOR I=1 TO LEN(Nm$)
'Convert the string to a number by summing the values
'of individual letters.
TmpVal = TmpVal + ASC(MID$(Nm$,I,1))
NEXT I
'Divide the sum by the size of the table.
HashValue = TmpVal MOD HASHTABSIZE
PRINT "The hash value is "; HashValue
'Sample Output
'
'Enter a name: Bafflegab
'The hash value is 66