Now I've found that my "optimized code" has a bug. When I loop from asc("a") to asc("z"), it returns the correct value for "a", but zeroes on all the others. I can't see the mistake.

I'm going to use Edgemeal's code but I still would like know where I erred in my code.