Bearpocalypse Posted April 3, 2014 Share Posted April 3, 2014 I'm trying to make life a little easier when scanning barcodes for some batteries for a recall. I have 10 entries I want to search. When using StringInStr, I can search for one and everything is fine and dandy. Can I assign one variable, say $BadItem to contain the 10 entries and have one StringInStr search? Let me know if I'm being stupid or if there is an easier way to do this. As always, thanks so for your help! Example $Serial = GUICtrlRead($B_Serial) ;Reads the input box $BadItem = 1 $BadItem = 2 $BadItem = 3 $BadItem = 4 $BadItem = 5 $BadItem = 6 $BadItem = 7 $BadItem = 8 $BadItem = 9 $BadItem = 10 $SerialFind = StringInStr($Serial, $BadItem) If $SerialFind Then MsgBox(0, '', 'Found a bad one.') Else MsgBox(0, '', 'This one is good.') EndIf Link to comment Share on other sites More sharing options...
JohnOne Posted April 3, 2014 Share Posted April 3, 2014 You need an array and a loop to check all values in it. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
mikell Posted April 3, 2014 Share Posted April 3, 2014 Or you can use StringRegExp with flag 0 The internal syntax will depend on the kind of the baditems to need to detect $Serial = "2a3b4c5e6d8i" $BadItem = "1a" $BadItem = "2b" $BadItem = "3c" $BadItem = "4d" $BadItem = "5e" $BadItem = "6f" $SerialFind = StringRegExp($Serial, '(1a|2b|3c|4d|5e|6f)', 0) If $SerialFind Then MsgBox(0, '', 'Found a bad one.') Else MsgBox(0, '', 'This one is good.') EndIf Link to comment Share on other sites More sharing options...
Bearpocalypse Posted April 4, 2014 Author Share Posted April 4, 2014 Thanks for the assistance. I actually got it working with a long 'StringInStr($, $) OR' statement. It works and we only need it for a short time. Link to comment Share on other sites More sharing options...
AutID Posted April 5, 2014 Share Posted April 5, 2014 If it is an InputBox() then you don't need GuiCtrlRead() to read it. As said at post you, loop an array and check all values. Local $B_Serial = InputBox("Hello", "Dump") Local $BadItem[10] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] For $i = 0 To UBound($BadItem) -1 If StringInStr($B_Serial, $BadItem[$i]) Then ConsoleWrite('Found a bad one.' & @LF) Else ConsoleWrite('This one is good.' & @LF) EndIf Next If it is an input(GUICtrlCreateInput()) then you will need GUICtrlRead() to read it's value. Anyway here you got the example with the array and the loop. It is much better than the long stringinstr thing you got it working https://iblockify.wordpress.com/ 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