Sign in to follow this  
Followers 0
MHz

Does StringInStr error ?

8 posts in this topic

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.

Share this post


Link to post
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.

Share this post


Link to post
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:

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

You indeed found the way to make it error, Valik. I was concerned on how it could ever come to error. Only to cover for a zero parameter. i guess it is good to cover all possibilites.

Thankyou, for the enlightenment. :lmao:

Share this post


Link to post
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.

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:

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0