Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21273

InStr Help - I B Confused

$
0
0
I an debugging some code from others that searches a string ( sBuffer) for a CRLF and then based on the result of the InStr executes something.

Here is the line of code that takes a look at the string and reports back:

Code:

  I = InStr(sBuffer, Chr(g_intFirstTerminatorASCII) & Chr(g_intSecondTerminatorASCII))
The code then uses the following statement to execute based on the result.

Code:

If I Then '[Do a calculation]

Else

End If

......


My Problem is that this statement executes the "Do a Calculation" if InStr returns an Integer result > 0 - the integer value indicating the position of the CRLF, BUT that it branches around the Do cals if the CRLF is NOT found. ( BTW this is what I want it to do)

From reading the syntax of the INstr though, I do not under stand HOW it does this. If the string is NOT found, the the syntax says that the InStr result is 0 - which I take to be the integer "0". I do not understand how the "If" knows to branch around. I was suprised to see that if the string is not found that InStr returns an integer. I would have thought it return be a true of false.

How does "I" being something greater than 0, do the calc and I = 0 branch.

I am confused by the use of the straight "I" . I would have been looking for If I >0 Then ....

This coder just used the "If I Then"

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


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

Return Values

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

Viewing all articles
Browse latest Browse all 21273

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>