This is quite possibly the most clever VBA code I have ever seen.
There's not much room for improvement here, except a couple naming nitpicks:
- If that's what they stand for, functions
shr
andshl
could afford to be calledShiftRight
andShiftLeft
. - I don't see a reason for
shr
andshl
to not follow the PascalCasing naming convention. - Given the almost-flawlessly consistent camelCasing convention for locals & parameters, I don't see a reason for
Value
andShift
parameters to not stick to it. (except perhaps VBA/VB6's stubornness with casing?)
As for string handling, as per this source AscW
is faster than Asc
so again, good call:
AscW(Mid$(..)) considerations
Don't copy too many characters with Mid$. AscW only examines the first character anyway. AscW(Mid$(s, x, 1)) is the best call. Note that if you call AscW(Mid$(s, x)) without the third parameter, Mid$ executes slowly when s is a long string.
Example of potentially slow code:
For x = 1 To Len(s) If AscW(Mid$(s, x)) = ... Then ... Next
The above is better written as:
For x = 1 To Len(s) If AscW(Mid$(s, x, 1)) = ... Then ... Next