MHz 80 Posted February 11, 2005 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
SlimShady 1 Posted February 11, 2005 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
MHz 80 Posted February 11, 2005 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 ? Share this post Link to post Share on other sites
Valik 478 Posted February 11, 2005 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
MHz 80 Posted February 11, 2005 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. Share this post Link to post Share on other sites
Jon 1,009 Posted February 11, 2005 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 Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Share this post Link to post Share on other sites
Valik 478 Posted February 11, 2005 (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 <{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. Edited February 11, 2005 by Valik Share this post Link to post Share on other sites
Blue_Drache 260 Posted February 11, 2005 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. <{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