Results 1 to 5 of 5
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    A FindNextOneOfThese Function

    Has anyone got a function that returns the location in a string of the next occurence of a list of chars?

    For example, if the instr function could do it, it might look like this:

    iPos = instr(i, strIn, " " or "." or "-" or " " or "/")
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A FindNextOneOfThese Function

    Got right on it Chief. How's this:
    <pre>Function EndofWord(strIn As String) As Long
    Dim n As Long
    For n = 1 To Len(strIn)
    Select Case Mid$(strIn, n, 1)
    Case " ", "-", "/"
    EndofWord = n - 1
    Exit For
    Case Else
    'Check next char for end of word
    End Select
    Next n
    End Function
    </pre>

    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Xiao Bin
    Guest

    Re: A FindNextOneOfThese Function

    VBA's built-in "Like" operator is always worth exploring for matching a character against a set of alternatives.

    For example,
    <pre>Function OrInstr(Start As Long, MainString As String, _
    Charset As String) As Long
    Dim iChar As Long

    For iChar = Start To Len(MainString)
    If Mid$(MainString, iChar, 1) Like Charset Then
    OrInstr = iChar
    Exit Function
    End If
    Next
    End Function
    </pre>


    Could be used to look for the first vowel in the word "hello". (The set of characters needs to be enclosed in square brackets"

    OrInstr(1,"hello","[aeiou]")

    Good luck !
    Xiao Bin

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: A FindNextOneOfThese Function

    Xiao,

    Very nice. Thanks. I think I'll put your code into service.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: A FindNextOneOfThese Function

    Hello Xiao Bin,

    'NewLounger' or no, I don't think you're a stranger to these precincts <g>. Here's hoping you'll have more opportunities to visit.

    Best regards,
    Gary

Posting Permissions

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