Results 1 to 7 of 7

Thread: InStr

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    InStr

    Hey,
    What does it mean when the InStr function returns the value 0. Sorry if you think it is a dumb question.

    Khanjan
    Hey... If you found this post helpful please rate it.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: InStr

    That the value you are looking for isnt in the search string.
    If on the other hand the return was say 5, it means that the first match from the Left is at the 5th position in the search string.

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: InStr

    MSDN (see also InStrRev()):
    InStr() Function
    See Also Example Specifics

    Returns a Variant (Long) specifying the position of the first occurrence of one string within another.

    Syntax

    InStr([start, ]string1, string2[, compare])

    The InStr function syntax has these arguments:

    Part Description
    start Optional. Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position. If start contains Null, an error occurs. The start argument is required if compare is specified.
    string1 Required. String expression being searched.
    string2 Required. String expression sought.
    compare Optional. Specifies the type of string comparison. If compare is Null, an error occurs. If compare is omitted, the Option Compare setting determines the type of comparison. Specify a valid LCID (LocaleID) to use locale-specific rules in the comparison.


    Settings

    The compare argument settings are:

    Constant Value Description
    vbUseCompareOption -1 Performs a comparison using the setting of the Option Compare statement.
    vbBinaryCompare 0 Performs a binary comparison.
    vbTextCompare 1 Performs a textual comparison.
    vbDatabaseCompare 2 Microsoft Access only. Performs a comparison based on information in your database.


    Return Values

    If InStr returns
    string1 is zero-length 0
    string1 is Null Null
    string2 is zero-length start
    string2 is Null Null
    string2 is not found 0
    string2 is found within string1 Position at which match is found
    start > string2 0

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: InStr

    For what it's worth, use the MSDN site - Here is InStr for example: http://msdn.microsoft.com/library/de...vafctInStr.asp

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Thumbs up InStr

    Well you are confusing me even more. Sorry. But here is the code.

    VB Code:
    1. Public Function GetLinks(s As String, baseURL As String) As String
    2.  
    3. start = InStr(1, s, "<a href=", vbTextCompare)
    4.  
    5. dq = Chr$(34)
    6. sq = Chr$(39)
    7.  
    8. Do
    9.    
    10.     pos = InStr(start, s, dq, vbTextCompare)
    11.     pos2 = InStr(start, s, sq, vbTextCompare)
    12.    
    13.     If pos = 0 and pos2 = 0 then Exit Do
    14.  
    15.     ' More stuff down here...
    16.  
    17. Loop While True
    18.  
    19. End Function

    Well basically, what the program is trying to do is look for links by finding html tags.

    From what I understand is that the following statement:

    VB Code:
    1. If pos = 0 and pos2 = 0 then Exit Do

    handles the part if the string being searched for i.e String 2 is not found in the main string i.e String 1

    Am I correct?

    Khanjan
    Hey... If you found this post helpful please rate it.

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: InStr

    You are looking for a start position of the "<a href=" within the 's' string, and then using that position to start the search locating dq, and sq values (if they exist). - Sound like you understand that from the post above.

    Now, your question. If the pos values (pos & pos2) equal 0, then neither were found in the string - s; so leave the Do/Loop. - having said that, that method is flawed unless you add the rest of the code to UPDATE the next Start position.

    There are tons of parse example posted here, particularly based on HTML Tags

  7. #7
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: InStr


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