Jump to content

Does StringInStr error ?


MHz
 Share

Recommended Posts

I have tried numerous ideas to fail StringInStr.

$result = StringInStr( "String", "z", 0, 1)
MsgBox(0, '', 'Error: ' & @error & '  |  Return: ' & $result)

I have changed parameters around, but keep getting @error = 0.

Could someone show me how to make it fail.

Link to comment
Share on other sites

It returns 0 when there's no match. That works fine for me.

It would be a nice addition if it would set @error.

<{POST_SNAPBACK}>

Maybe it should be setting error ?

Success: Returns the position of the substring.

Failure: Returns 0 if substring not found.

@Error 0 - Normal operation

            1 - Occurance was 0. Occurance must be a positive or negative integer.

So, failure should be checked by return ? Is @error in the helpfile by mistake. Or is @error broken ? :lmao:
Link to comment
Share on other sites

If occurance is 0, then @error will be set. No other reason will cause it to be set. Your example has 1 as the occurance. This will fail and set @error:

$result = StringInStr( "String", "z", 0, 0)
MsgBox(0, '', 'Error: ' & @error & '  |  Return: ' & $result)

It is not an error for the sub-string to not be in the string. Thats perfectly normally behavior for the function. In this case, @error is reserved for a trully erroneous situation where the user is a moron and wants the 0th occurance of the string. Any other combination of parameters can produce a valid match/no-match situation as returned by the return value.

Link to comment
Share on other sites

  • Administrators

If occurance is 0, then @error will be set.  No other reason will cause it to be set.  Your example has 1 as the occurance.  This will fail and set @error:

$result = StringInStr( "String", "z", 0, 0)
MsgBox(0, '', 'Error: ' & @error & '  |  Return: ' & $result)

It is not an error for the sub-string to not be in the string.  Thats perfectly normally behavior for the function.  In this case, @error is reserved for a trully erroneous situation where the user is a moron and wants the 0th occurance of the string.  Any other combination of parameters can produce a valid match/no-match situation as returned by the return value.

You can always tell which code Nutster has done, he likes to give errors for daft input whereas I prefer just to tell them it failed and let them work it out :lmao:
Link to comment
Share on other sites

You can always tell which code Nutster has done, he likes to give errors for daft input whereas I prefer just to tell them it failed and let them work it out o:)

<{POST_SNAPBACK}>

I wish @extended could accept strings. I'd be putting all kinds of fun messages for stuff like this such as, "user is a dumbass, 0th string can't exist".

Edit: Yes, CyberSlug, I'm "borrowing" your idea. :lmao:

Edited by Valik
Link to comment
Share on other sites

I wish @extended could accept strings.  I'd be putting all kinds of fun messages for stuff like this such as, "user is a dumbass, 0th string can't exist".

Edit: Yes, CyberSlug, I'm "borrowing" your idea. :lmao:

<{POST_SNAPBACK}>

Roffles, I'd actually love to see something like that...but who uses, or much less even VEIWES @extended? I never have...although it'd be nice for setting like you suggested in UDF's

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...