Hi,
I've got a basic instr count function, can anyone see any flaws in it or any way of tweaking it to make it more efficient without making api calls etc.
VB Code:
Private Sub Command1_Click() Debug.Print InStrCount("the quick brown fox jumped over the lazy dog", " ") & vbNewLine End Sub Private Function InStrCount(ByVal Expression As String, _ ByVal Find As String, _ Optional ByVal Start As Long = 1, _ Optional ByVal Count As Long = -1, _ Optional Compare As VbCompareMethod = vbBinaryCompare) As Long Dim Temp$, h As Long On Error Resume Next ' handle div by zero Temp$ = Replace(Expression, Find, "", Start, Count, Compare) h = CLng(LenB(Expression) - LenB(Temp$)) h = CLng(h \ LenB(Find)) InStrCount = h End Function
Any help or pointers will be gratefully received
Cheers Al




Reply With Quote