Hey,
What does it mean when the InStr function returns the value 0. Sorry if you think it is a dumb question.
Khanjan
Printable View
Hey,
What does it mean when the InStr function returns the value 0. Sorry if you think it is a dumb question.
Khanjan
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.
MSDN (see also InStrRev()):
Quote:
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
For what it's worth, use the MSDN site - Here is InStr for example: http://msdn.microsoft.com/library/de...vafctInStr.asp
Well you are confusing me even more. Sorry. But here is the code.
VB Code:
Public Function GetLinks(s As String, baseURL As String) As String start = InStr(1, s, "<a href=", vbTextCompare) dq = Chr$(34) sq = Chr$(39) Do pos = InStr(start, s, dq, vbTextCompare) pos2 = InStr(start, s, sq, vbTextCompare) If pos = 0 and pos2 = 0 then Exit Do ' More stuff down here... Loop While True 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:
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
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 :)
Here is an alternate method: http://www.vbforums.com/showthread.p...highlight=tags