Results 41 to 73 of 73

Thread: instr Count

Threaded View

  1. #1

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Resolved instr Count

    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:
    1. Private Sub Command1_Click()
    2.     Debug.Print InStrCount("the quick brown fox jumped over the lazy dog", " ") & vbNewLine
    3. End Sub
    4.  
    5. Private Function InStrCount(ByVal Expression As String, _
    6.                         ByVal Find As String, _
    7.                         Optional ByVal Start As Long = 1, _
    8.                         Optional ByVal Count As Long = -1, _
    9.                         Optional Compare As VbCompareMethod = vbBinaryCompare) As Long
    10.     Dim Temp$, h As Long
    11.     On Error Resume Next ' handle div by zero
    12.     Temp$ = Replace(Expression, Find, "", Start, Count, Compare)
    13.     h = CLng(LenB(Expression) - LenB(Temp$))
    14.     h = CLng(h \ LenB(Find))
    15.     InStrCount = h
    16. End Function

    Any help or pointers will be gratefully received

    Cheers Al
    Last edited by aconybeare; Jun 23rd, 2005 at 03:04 AM. Reason: Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width