All right, when writing an algorithm, the trick is to make it right before you make it faster. Now that we have the desired functionality in place, our next step is to optimize.
StrConv() is a handy function, but it is an expensive function, and we don't need it in this case. While the resulting function might be a little harder to follow, as you only want to flip the bytes on every other element in the coerced byte array, the results might just be worth it, especially on smaller strings.
So, with this in mind, we make the following adjustments:
<font face=Courier New><SPAN style="color:darkblue">Public</SPAN> <SPAN style="color:darkblue">Function</SPAN> sCase(<SPAN style="color:darkblue">ByRef</SPAN> strIn <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> bArr() <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Byte</SPAN>, i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, i2 <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>
<SPAN style="color:darkblue">If</SPAN> strIn = vbNullString <SPAN style="color:darkblue">Then</SPAN> <SPAN style="color:darkblue">Exit</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Let</SPAN> bArr = strIn
<SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> bArr(0)
<SPAN style="color:darkblue">Case</SPAN> 97 <SPAN style="color:darkblue">To</SPAN> 122
bArr(0) = bArr(0) - 32
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">For</SPAN> i = 2 <SPAN style="color:darkblue">To</SPAN> <SPAN style="color:darkblue">UBound</SPAN>(bArr) <SPAN style="color:darkblue">Step</SPAN> 2
<SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> bArr(i)
<SPAN style="color:darkblue">Case</SPAN> 105
<SPAN style="color:darkblue">If</SPAN> <SPAN style="color:darkblue">Not</SPAN> i = <SPAN style="color:darkblue">UBound</SPAN>(bArr) - 1 <SPAN style="color:darkblue">Then</SPAN>
<SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> bArr(i + 2)
<SPAN style="color:darkblue">Case</SPAN> 32, 33, 39, 44, 46, 58, 59, 63, 148, 160
<SPAN style="color:darkblue">If</SPAN> bArr(i - 2) = 32 Then _
bArr(i) = bArr(i) - 32
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">ElseIf</SPAN> bArr(i - 2) = 32 Then _
bArr(i) = bArr(i) - 32
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">If</SPAN>
<SPAN style="color:darkblue">Case</SPAN> 33, 46, 58, 63
<SPAN style="color:darkblue">For</SPAN> i2 = i + 2 <SPAN style="color:darkblue">To</SPAN> <SPAN style="color:darkblue">UBound</SPAN>(bArr) <SPAN style="color:darkblue">Step</SPAN> 2
<SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> bArr(i2)
<SPAN style="color:darkblue">Case</SPAN> 97 <SPAN style="color:darkblue">To</SPAN> 122
bArr(i2) = bArr(i2) - 32
i = i2: <SPAN style="color:darkblue">Exit</SPAN> <SPAN style="color:darkblue">For</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">Select</SPAN> <SPAN style="color:darkblue">Case</SPAN> bArr(i2)
<SPAN style="color:darkblue">Case</SPAN> 32, 33, 46, 63, 160
<SPAN style="color:darkblue">Case</SPAN> <SPAN style="color:darkblue">Else</SPAN>
i = i2: <SPAN style="color:darkblue">Exit</SPAN> <SPAN style="color:darkblue">For</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">Next</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">Next</SPAN>
sCase = bArr
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Function</SPAN>
<SPAN style="color:darkblue">Sub</SPAN> testTime()
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase(LCase$("hello? erm, i<SPAN style="color:green">'M only testing, eh. indeed, " & _
"i am inquisitve."))</SPAN>
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase(LCase$("how old?! 22 Years."))
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase(LCase$("how old?! twenty-two Years."))
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase(LCase$("hmmmm.... wOrking?!?! sam i am. yes-no? " & _
"isn<SPAN style="color:green">'t i'm isn't."))</SPAN>
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase(LCase$("THE DAY WAS SUNNY AND I WORE A HAT.PETER WAS THERE "))
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase(LCase$("no WorRies, i<SPAN style="color:green">'m ONLY testIng! yes-no?"))</SPAN>
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase(LCase$("mY fRiend & i"))
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase(LCase$("iiiiiiiiiiiiii"))
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase(LCase$("***T. toast %T i @"))
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase(LCase$("re: sentences."))
<SPAN style="color:darkblue">Debug</SPAN>.<SPAN style="color:darkblue">Print</SPAN> sCase("hello? thought i<SPAN style="color:green">'d test this for David McRitchie. NOTHING.")</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>
I haven't tested the code with a high-resolution timer, while I could, but on small strings I would imagine it's quite a bit faster than its predecessor (which was pretty fast to begin with).