I needed to do some work with barcodes recently, specifically I needed to handle Code 39 Mod 43 barcodes.

Given a barcode string this function should return the relevant Mod 43 checksum.

  1. public class Code39
  2.     {
  3.         ///
  4.         ///Returns the expected checksum for the specified barcode
  5.         ///
  6.         ///
  7.         ///
  8.         public string ValidateMod43(string barcode)
  9.         {
  10.             int subtotal = 0;
  11.             const string charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
  12.  
  13.             for (int i = 0; i < barcode.Length; i++)
  14.             {
  15.                 subtotal += charSet.IndexOf(barcode.Substring(i, 1));
  16.             }
  17.  
  18.             return charSet.Substring(subtotal%43, 1);
  19.         }
  20.     }

I adapted this from a VBA script so if there’s a better way of doing it let me know!

Stuck every time you jump out of the tutorials?

Make 2019 the year you finally conquer all those controllers, views, models and all that other "stuff" that comes with MVC.

You'll also get ASP.NET advice, guidance and useful tips from me once a week (or so). I respect your email privacy, unsubscribe at any time.

Stuck every time you jump out of the tutorials?

Stop wasting time trying to learn ASP.NET Core MVC and fast forward to the fun bit (building your features)

Can't make sense of front-end development?

Check out Front-end in four hours for a head-start

Take a look

Stuck every time you jump out of the tutorials?

Make 2019 the year you finally conquer all those controllers, views, models and all that other "stuff" that comes with MVC.

You'll also get ASP.NET advice, guidance and useful tips from me once a week (or so). I respect your email privacy, unsubscribe at any time.