+ Reply to Thread
Results 1 to 3 of 3

thoroughly-baffled by InStr function w/ binary compare

  1. #1
    terry b
    Guest

    thoroughly-baffled by InStr function w/ binary compare

    Hello, all
    [Using the simple example from the vba help files, the following
    returns 9:]
    Sub StringPractice()
    Dim SearchString, SearchChar, MyPos
    SearchString = "XXpXXpXXPXXP" ' String to search in.
    SearchChar = "P" ' Search for "P".
    ' A binary comparison starting at position 1. Returns 9.
    MyPos = InStr(1 , SearchString, SearchChar, 0)
    MsgBox MyPos
    End Sub

    Obviously the first occurrence of "P" is in the 9 pos when starting at
    beginning of SearchString... BUT WHY, when I substitute any other
    number for a starting position, click on reset, then run sub again,
    does the answer ALWAYS RETURN A 9??? Does the constant vbBinaryCompare
    not support the use a starting-position number w/ InStr???
    Thanks much for your time [:-))

    terry b.


  2. #2
    RWN
    Guest

    Re: thoroughly-baffled by InStr function w/ binary compare

    Unless your starting # is > 9 then it will always return 9.
    The starting position is just that, the start position for the search.
    Start in pos one, finds the 1st instance of "P" at pos 9.
    Start in pos nine, finds the 1st instance of "P" at pos 9 (same "P").
    Start in pos ten, finds the 1st instance of "P" (from pos 10 to the end of the string) at
    pos 12 ( "P").

    --
    Regards;
    Rob
    ------------------------------------------------------------------------
    "terry b" <[email protected]> wrote in message
    news:[email protected]...
    > Hello, all
    > [Using the simple example from the vba help files, the following
    > returns 9:]
    > Sub StringPractice()
    > Dim SearchString, SearchChar, MyPos
    > SearchString = "XXpXXpXXPXXP" ' String to search in.
    > SearchChar = "P" ' Search for "P".
    > ' A binary comparison starting at position 1. Returns 9.
    > MyPos = InStr(1 , SearchString, SearchChar, 0)
    > MsgBox MyPos
    > End Sub
    >
    > Obviously the first occurrence of "P" is in the 9 pos when starting at
    > beginning of SearchString... BUT WHY, when I substitute any other
    > number for a starting position, click on reset, then run sub again,
    > does the answer ALWAYS RETURN A 9??? Does the constant vbBinaryCompare
    > not support the use a starting-position number w/ InStr???
    > Thanks much for your time [:-))
    >
    > terry b.
    >




  3. #3
    terry b
    Guest

    Re: thoroughly-baffled by InStr function w/ binary compare

    Hello, Rob
    I have no clue as to why I was ASSUMING that the position the
    sought-after string would be found would be RELATIVE to the start
    position! Thanks much for clearing up that little problem!
    Regards,
    terry b


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1