MHz Posted February 11, 2005 Share 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. Link to comment Share on other sites More sharing options...
SlimShady Posted February 11, 2005 Share 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. Link to comment Share on other sites More sharing options...
MHz Posted February 11, 2005 Author Share 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 ? Link to comment Share on other sites More sharing options...
Valik Posted February 11, 2005 Share 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. Link to comment Share on other sites More sharing options...
MHz Posted February 11, 2005 Author Share 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. Link to comment Share on other sites More sharing options...
Administrators Jon Posted February 11, 2005 Administrators Share 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/ Link to comment Share on other sites More sharing options...
Valik Posted February 11, 2005 Share 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 Link to comment Share on other sites More sharing options...
Blue_Drache Posted February 11, 2005 Share 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now