VINChecker.frink

Download or view VINChecker.frink in plain text format


// Checks VIN numbers checksum using the procedure found at:
// http://www.vehicleidentificationnumber.com/NHTSA_vehicle_identification_number_content.html

class VINChecker
{
   class var d = undef

   class var weights = [8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2]
   
   class calculateVINChecksum[vin] :=
   {
      if d==undef
         initCharMap[]
      
      sum = 0
      for pos = 0 to 16
      {
         c = substrLen[vin, pos, 1]
         println["Char at " + (pos+1) + " is $c, value is " + d@c]
         sum = sum + d@c * weights@pos
      }

      println["Sum is $sum"]
      checksum = sum mod 11

      if checksum == 10
         checksum = "X"
      else
         checksum = "$checksum"
   }

   class initCharMap[] :=
   {
      d = new dict

      d@"0" = 0
      d@"1" = 1
      d@"2" = 2
      d@"3" = 3
      d@"4" = 4
      d@"5" = 5
      d@"6" = 6
      d@"7" = 7
      d@"8" = 8
      d@"9" = 9
      d@"A" = 1
      d@"B" = 2
      d@"C" = 3
      d@"D" = 4
      d@"E" = 5
      d@"F" = 6
      d@"G" = 7
      d@"H" = 8
      d@"I" = undef
      d@"J" = 1
      d@"K" = 2
      d@"L" = 3
      d@"M" = 4
      d@"N" = 5
      d@"O" = undef
      d@"P" = 7
      d@"Q" = undef
      d@"R" = 9
      d@"S" = 2
      d@"T" = 3
      d@"U" = 4
      d@"V" = 5
      d@"W" = 6
      d@"X" = 7
      d@"Y" = 8
      d@"Z" = 9

      return d
   }
}

vin = trim[input["Enter VIN: "]]

checksum = VINChecker.calculateVINChecksum[vin]
println["Calculated checksum is:   $checksum"]
println["Digit in original VIN is: " + substrLen[vin,8,1]]


Download or view VINChecker.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 20217 days, 23 hours, 24 minutes ago.